解析. cloud . httprequest响应gzip膨胀/解压



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

在parse.com上,我从未遇到过接收XML文件的问题,但在不同的主机(back4app)上使用解析服务器,我的httpResponse。文本是一堆:

�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);
        }
    });
}

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

最新更新