小编Pm *_*ère的帖子

来自节点url请求的无效字符(非UTF-8)但是从浏览器有效吗?

我在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有关吗?

我怎样才能解决这个问题?

utf-8 request node.js google-places-api

3
推荐指数
1
解决办法
3079
查看次数

标签 统计

google-places-api ×1

node.js ×1

request ×1

utf-8 ×1