2016-08-25 33 views
0

Parse.Cloud.httpRequest如何处理压缩?Parse.Cloud.httpRequest响应gzip膨胀/解压

在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); 
     } 
    }); 
} 
+0

分析是不是一个网络服务器,我想你应该在你的nginx或Apache配置它... –

+0

尝试处理一个zip'd响应.... http://stackoverflow.com/questions/12148948/怎么办-I-ungzip - 解压缩-A-的NodeJS,请求模块,用gzip响应体 –

回答

0

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

基本上,选择gzip的:真正的没有记录任何地方,但需要。

我不确定是否需要标题,但我仍然留下它们。

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) { 
      ... 
     } 
}