相关疑难解决方法(0)

你什么时候应该使用escape而不是encodeURI/encodeURIComponent?

编码要发送到Web服务器的查询字符串时 - 何时使用escape()以及何时使用encodeURI()encodeURIComponent():

使用转义:

escape("% +&=");
Run Code Online (Sandbox Code Playgroud)

要么

使用encodeURI()/ encodeURIComponent()

encodeURI("http://www.google.com?var1=value1&var2=value2");

encodeURIComponent("var1=value1&var2=value2");
Run Code Online (Sandbox Code Playgroud)

javascript encoding query-string

1371
推荐指数
11
解决办法
45万
查看次数

你如何通过URL传递撇号?

我正在使用Node.js:

var s = 'Who\'s that girl?';
var url = 'http://graph.facebook.com/?text=' + encodeURIComponent(s);

request(url, POST, ...)
Run Code Online (Sandbox Code Playgroud)

这不起作用!Facebook切断了我的文字......

完整代码:

function postToFacebook(fbid, access_token, data, next){
    var uri = 'https://graph.facebook.com/'+String(fbid)+'/feed?access_token='+access_token;
    var uri += '&' + querystring.stringify(data);
    request({
        'method':'POST',
        'uri': uri,
    },function(err,response,body){
        next();
    });
};


app.get('/test',function(req,res){
    var d = {
        'name':'Who\'s that girl?',
        'link': 'http://example.com',
        'caption': 'some caption...',
        'description': 'some description...',
        'picture': 'http://i.imgur.com/CmlrM.png',
    };
    postToFacebook(req.user.fb.id, req.user.fb.accessToken, d);
    res.send('done');
});
Run Code Online (Sandbox Code Playgroud)

Facebook在墙上发布了一个空白帖子.没有文字显示.没有.

当我记录我的URI时,它是这样的:

https://graph.facebook.com/1290502368/feed?access_token=2067022539347370|d7ae6f314515c918732eab36.1-1230602668|GtOJ-pi3ZBatd41tPvrHb0OIYyk&name=Who's%20that%20girl%3F&link=http%3A%2F%2Fexample.com&caption=some%20caption...&description=some%20description...&picture=http%3A%2F%2Fi.imgur.com%2FCmlrM.png
Run Code Online (Sandbox Code Playgroud)

显然,如果您查看该URL,您会看到撇号未正确编码.

javascript string encoding node.js facebook-graph-api

24
推荐指数
3
解决办法
8万
查看次数