编码要发送到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) 我想对URL进行编码:
SELECT name FROM user WHERE uid = me()
Run Code Online (Sandbox Code Playgroud)
我必须为此下载模块吗?我已经有了请求模块.
我在Node js中使用Request来调用Google Place api Web服务.请求正文出错,Invalid request. One of the input parameters contains a non-UTF-8 string.因为我在url参数(keyword参数)中使用高棉字符.
nearByUrl = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=11.55082623,104.93225202&radius=400&keyword=????????????&key=' + MY_KEY;
request({
url: nearByUrl,
json: true
}, function (error, response, body) {
console.log(JSON.stringify(body, null, 2));
})
Run Code Online (Sandbox Code Playgroud)
但是,当使用Chrome浏览器中的高棉字符调用完全相同的URL时,我可以获得有效的JSON结果.
这个问题与Request有关吗?
我怎样才能解决这个问题?