如何通过网址传递单引号? [英] How do you pass a single quote through a URL?
问题描述
我正在使用 Node.js :
var s ='那个女孩是谁?
var url ='http://graph.facebook.com/?text='+ encodeURIComponent(s);
请求(url,POST,...)
工作!而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);
请求({
'method':'POST',
'uri':uri,
},function(err,response,body){
next );
});
};
app.get('/ test',function(req,res){
var d = {
'name':'Who?那个女孩?',
'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');
});
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
/ pre>
显然,如果你看看那个URL,你会发现单引号没有被正确编码。
解决方案我正在做一个类似的事情(也是使用Node.js),并且首先尝试使用JavaScript的内置 escape()函数,但它没有真正的工作。
以下是我最终得到搜索工作的方式。这可能只是一个琐事:
function doMySearch(showTitle){
showTitle = escapeShowTitle(showTitle)
var url =http://graph.facebook.com/search?q=+ showTitle +& type = page
doSomethingWith(url)
}
函数escapeShowTitle(title){
title = title.replace(/'/ g,)
title = escape(title)
return title
}
doMySearch(美国最有趣的家庭影片)
I'm using Node.js:
var s = 'Who\'s that girl?'; var url = 'http://graph.facebook.com/?text=' + encodeURIComponent(s); request( url, POST, ...)
This does not work! And Facebook cuts off my text...
Full code:
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'); });
Facebook gets a blank post on the wall. No text shows. Nothing.
When I log my URI, it is this:
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
Obviously if you take a look at that URL, you see that the single quote is not being encoded correctly.
解决方案I'm doing a similar thing (also with Node.js) and first tried using JavaScript's built-in escape() function, but it didn't really work.
Here's how I ended up getting search to work. It might just be a fluke:
function doMySearch(showTitle) { showTitle = escapeShowTitle(showTitle) var url = "http://graph.facebook.com/search?q=" + showTitle + "&type=page" doSomethingWith(url) } function escapeShowTitle(title) { title = title.replace(/'/g, "") title = escape(title) return title } doMySearch("America's Funniest home Videos")
这篇关于如何通过网址传递单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!