0

Is there something different in how Parse.Cloud.httpRequest is handling compression ?

On parse.com, I never had an issue with receiving a XML file, but using parse server on a different host (back4app), my httpResponse.text is a load of:

�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);
        }
    });
}
NSNoob
  • 5,548
  • 6
  • 41
  • 54
Johnny Zen
  • 76
  • 5
  • parse is not a webserver, I think you should configure it in your nginx or apache... – Mazel Tov Aug 25 '16 at 16:46
  • try handling a zip'd response .... http://stackoverflow.com/questions/12148948/how-do-i-ungzip-decompress-a-nodejs-requests-module-gzip-response-body – Robert Rowntree Aug 25 '16 at 20:48

1 Answers1

0

Thanks for the great support at back4app, here is the solution

Basically, the option gzip:true is not documented anywhere but is needed.

I am not sure if the headers are needed, but I left them in anyway.

 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) {
           ...
      }
 }
Johnny Zen
  • 76
  • 5