I'm trying to retrieve answer data via the StackExchange API. So far I've found the URL I want to pull from my application and in the browser it returns the expected data in plain text, JSON format.
This returns the expected data
{"items":[{"owner":{"display_name":"AJFaraday"},"answer_id":18633,"body":"<h1>My Answer</h1>\n\n<pre><code>class...
The problem is, when I try to access this same URL from my code (a NodeJS application, using the https module), the returned body data is showing some nonsense chars, presumably raw data, instead of the expected plain text.
Here's the JS code I'm trying out, using the request library in NodeJS.
const request = require('request');
this.url = 'https://api.stackexchange.com/2.2/questions/' + question_id +
'/answers?site=' + site + '&filter=!.FjsvG2X2tViZPCgDuGvW88wrGptD';
request(
this.url,
{json: true},
function (err, res, body) {
if (err) {
return console.log(err);
}
console.log(body);
}
);
I can reproduce this with curl to show you the data I'm recieving...
$ curl 'https://api.stackexchange.com/2.2/questions/18632/answers?site=codegolf.meta&filter=!.FjsvG2X2tViZPCgDuGvW88wrGptD'
�
|�Qk�0ǿʑ�QZ�s��܃?�J��لդ$鴔~����@r����?�a�dH�m�:K�$�,h�JzB��ךj�hMڀPiΨS�HM�dJ���*�I���2���Jc�C�raBS*�*
#p���P�CM%S'χ�̝��,����#^?�9��[�x�n���8�:X������9��#���G���o��^���`ō�-{���D���v
��[�N�v����yi��:[
Why is this behaving differently in the browser and programatic requests?
Do I need to indicate something about text encoding in my request?
What am I missing here?