在查询字符串 NodeJS 和请求模块中传递重音字符
Pass Accent character in querystring NodeJS and Request Module
我在我的 nodejs express 应用程序中使用 Request 模块,我需要在查询字符串中传递任何重音字符(例如:josé),但是当其他客户端收到请求时,它会收到一个未知字符(?)。
如果我通过浏览器或邮递员传递相同的 url,客户端将获得正确的重音字符。
var request = require('request-promise');
var url = 'http://mypathtotheurl?var=josé';
const optionsStart = {
url: url,
method: "GET",
encoding: "binary",
headers: {
"Content-type": "applcation/pdf"
}
};
request(optionsStart).then(function(body, data) {
//my logic working as expected except for show special chars
}
用浏览器或邮递员得到正确的响应,通过请求模块得到未知字符
我在请求方法中找到了一个包含 url 的快速解决方案:
var url = 'http://mypathtotheurl?var=josé';
url = encodeURI(url)
我在我的 nodejs express 应用程序中使用 Request 模块,我需要在查询字符串中传递任何重音字符(例如:josé),但是当其他客户端收到请求时,它会收到一个未知字符(?)。
如果我通过浏览器或邮递员传递相同的 url,客户端将获得正确的重音字符。
var request = require('request-promise');
var url = 'http://mypathtotheurl?var=josé';
const optionsStart = {
url: url,
method: "GET",
encoding: "binary",
headers: {
"Content-type": "applcation/pdf"
}
};
request(optionsStart).then(function(body, data) {
//my logic working as expected except for show special chars
}
用浏览器或邮递员得到正确的响应,通过请求模块得到未知字符
我在请求方法中找到了一个包含 url 的快速解决方案:
var url = 'http://mypathtotheurl?var=josé';
url = encodeURI(url)