如何只更改请求url查询编码?

时间:2017-01-24 17:31:24

标签: node.js encoding request

我将来自nodejs的请求发送到服务器,并在我的网址中查询西里尔文本,如下所示:https://somesite.com/wf/server/postSomeStuff?id=13&name=Имя.pdf&other=true; 但服务器请ИмяA;>1>60=I8=0类似。 (例如)。我想让这个查询编码为unicode。我试图设置Accept-CharsetAccept-Encoding之类的标题,但它没有帮助..如何仅在网址中更改编码,而不是内容?

1 个答案:

答案 0 :(得分:1)

您可以在发送请求之前使用javascript encodeURI函数

var url ='https://somesite.com/wf/server/postSomeStuff?id=13&name='+ encodeURI('Имя.pdf')+'& other = true';

并在服务器端解码它 var name = decodeURI(req.params.name);