0

I'm making an ajax request using the 'request' node package and it has worked elsewhere in my application when making calls from other APIs however when I'm making a request to this specific API I get bodies that look like this:

�5�Ak1���0^����B�y��A�J�hf���H��*K��#�����e�7#�bB������뻡���p��I�9�ࢣ��o�Fg?�G��ä�5Ї�u��j���n�Z)�UJ;����ű��Z�賢f�,�hEޥ��((�$�xp��'q�Į�Ykc�)L�TOm��>d�/�R�o���,��

Below shows my code:

const requestOptions = {
  url: 'CORRECTLYFORMATEDURL',
};
request(requestOptions, function (error, response, body) {
  fs.writeFile("test.txt", body, function(err) {
     if(err) {
       return console.log(err);
     }

     console.log("The file was saved!");
  });
});

If I enter this url into a web browser I get a correctly formatted JSON object which is why this isn't making any sense to me.

teamyates
  • 414
  • 1
  • 7
  • 25
  • 2
    When you do the test in the browser, did you check the HTTP response headers to see if there's anything interesting? It might be compressed. If you have access to a Linux/Unix command line you could check the saved file with the `file` command. – Pointy Jun 14 '19 at 13:15
  • 2
    https://stackoverflow.com/questions/8880741/node-js-easy-http-requests-with-gzip-deflate-compression – Clive Jun 14 '19 at 13:16

0 Answers0