Parse.com/Nodejs http-request删除特殊字符

Parse.com/Nodejs http-request special characters removed

本文关键字:删除 特殊字符 http-request Nodejs com Parse      更新时间:2023-09-26

我通过parse.com(这是建立在nodejs上的)访问亚马逊的MWS-Api,并且与他们的flatfile-reports (getreport端点)有问题。删除所有特殊字符(ä、ö、ü)。根据MWS-Support,他们正在使用cp1252编码。这是请求代码。

// Parse.Cloud.httpRequest is parses version of the nodejs http-module
Parse.Cloud.httpRequest({
    url: "https://mws.amazonservices.de/?",
    method: "POST",
    headers: {
        "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
        "Host": "mws.amazonservices.de",
        "x-amazon-user-agent": "MyUserAgent(Language=Javascript)",
        "Accept-Charset": "CP1252"
    },
    body: queryString
    success: function(resp){
            response.success(resp)
        }
    },
    error: function(err){
        response.error(err)
    }

我收到的响应头如下所示:

  {
  "Connection": "close",
  "Content-Length": "395828",
  "Content-MD5": "Xw8KYGqESc7u4TTzgcbT/g==",
  "Content-Type": "text",
  "Date": "Thu, 13 Aug 2015 10:21:00 GMT",
  "Server": "AmazonMWS",
  "Vary": "Accept-Encoding,User-Agent",
  "x-amz-request-id": "xxxxx",
  "x-mws-quota-max": "60.0",
  "x-mws-quota-remaining": "58.0",
  "x-mws-quota-resetsOn": "2015-08-13T10:38:00.000Z",
  "x-mws-request-id": "xxxxx",
  "x-mws-response-context": "C0ywPcTe0K9qESsoz4OzZX9oRJMDuYR9vvk5MfN3KKOGEnyWgSZlOQDixINemnwLVZl0DjXEdrY=",
  "x-mws-timestamp": "2015-08-13T10:21:01.186Z"
}

澄清一下,特殊字符没有被乱码(没有"-"或类似的东西)。"Fr"被简单地接收为"Fr"。奇怪的是,我在使用amazon scratchpad (https://mws.amazonservices.de/scratchpad/index.html)时也遇到了同样的问题,根据MWS-Support,它应该能够正确地显示特殊字符。谢谢你的帮助。

edit1:另外,我的一个同事在一个完全不相关的项目(所有的数据源都不同)中有一个非常类似的解析问题。在用python进行了一些实验之后,我相当确定他的数据提要是用latin1编码的,而不是utf8,这似乎是导致问题的原因。在解析中强制执行latin1或CP1252编码的任何方法?

Amazon的支持人员确认了这是他们这边的一个bug,据我所知,他们已经修复了这个bug。

您已经请求parse.com以utf-8格式向您发送数据。

注意以下几行:

    "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
    "Accept-Charset": "utf-8"

将这些值更改为latin1可能有效,如果您可以与您的同事比较。

然而,在parse.com论坛上的这个问题可能会对你的问题有所帮助。这可能是客户(你)方面的问题。你试过改变你那边的编码吗?