【问题标题】:Pass Accent character in querystring NodeJS and Request Module在查询字符串 NodeJS 和请求模块中传递重音字符
【发布时间】:2019-04-03 05:31:29
【问题描述】:

我在我的 nodejs express 应用程序中使用请求模块,我需要在查询字符串中传递任何重音字符(例如: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
     }

通过浏览器或邮递员得到正确的响应,通过请求模块得到未知字符

【问题讨论】:

    标签: node.js url request query-string


    【解决方案1】:

    我找到了一个在请求方法中包含 url 的快速解决方案:

    var url = 'http://mypathtotheurl?var=josé';
    
    url = encodeURI(url)
    

    【讨论】:

      猜你喜欢
      • 2019-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-19
      相关资源
      最近更新 更多