如何使用NodeJS-JSON在post方法上转义重音字符

时间:2018-11-29 23:28:56

标签: javascript node.js utf-8 char escaping

我需要将字符串转义为“città”或更复杂的字符串,例如“ lacittàdi Roma”。 我正在通过POST方法以JSON格式的消息将此字符串发送到远程Web服务。 我使用querystring.escape(),但无法使远程服务器正确对其进行解码,实际上,它接收的是“ city。”而不是“città”。 我尝试将字符串发送为“ citt \ u00e0”,并将字符串.SetEncoding设置为UTF-8,但是没有办法。

这是代码:

let strRicerca='città; //  citt\u00e0

strRicerca.setEncoding='UTF-8';
strRicerca=querystring.escape(strRicerca);


  const options = {
    hostname: 'XX.xx.xx.xx, 
    port: 8080, 
    path: '/path/to/service?searchText='+strRicerca+'&user=&pwd=&ava=XX',
    method: 'POST', 
    headers: {
      'Content-Type': 'application/json',
      'Content-Length': Buffer.byteLength(postData),
      'Cookie':'JSESSIONID='+sessione   
    }
  };
console.log('path ' + options.path);

我想念什么?

预先感谢

0 个答案:

没有答案