Parse.Cloud.httpRequest响应gzip通胀/解压缩

时间:2016-08-25 15:50:45

标签: parse-platform server

Parse.Cloud.httpRequest处理压缩的方式有什么不同吗?

在parse.com上,我从未遇到过接收XML文件的问题,但在另一台主机上使用解析服务器(back4app),我的httpResponse.text是一个加载:

�E��ڇ�*q�������y���v^�����

Parse.Cloud.job("fetchData", function(request, status) {
Parse.Cloud.httpRequest({
        method: 'GET',
        url: 'http://example.com/test.xml',
        headers: {
            'Accept': 'application/xml',
            'Accept-Encoding': 'gzip, deflate'
        },
        success: function (httpResponse) {
            console.log("SUCCESS RECD FILE: " + httpResponse.text);
        },
        error: function (httpResponse) {
            console.log('An error has occured with the http request.: ' + httpResponse);
        }
    });
}

1 个答案:

答案 0 :(得分:0)

感谢back4app的大力支持,这是解决方案

基本上,选项 gzip:true 没有在任何地方记录,但是需要。

我不确定是否需要标题,但我还是留了它们。

 Parse.Cloud.httpRequest({

      url: 'http://example.com/feed.xml',
      headers: { 
           'Content-Type': 'application/xml',
           'Accept-Encoding': 'gzip, deflate' 
      },
      gzip:true,
      success: function (httpResponse) {
           ...
      },
      error: function (httpResponse) {
           ...
      }
 }
相关问题