I have a particularly interesting issue, So I am trying to use Stackoverflow Search/Advanced API to query stackoverflow to get questions. I have tried it using PostMan and its returning JSON but in my Node.js application it is returning me raw data.
exports.GetQuestions = function(query,requestify)
{
var request = require("request");
var options = { method: 'GET',
url: 'https://api.stackexchange.com/2.2/search/advanced',
qs:
{ order: 'desc',
sort: 'activity',
site: 'stackoverflow',
q: 'Error: Can\'t find Python executable
"C:\\Users\\harig\\AppData\\Local\\Programs\\Python\\Python36\\python.EXE",
you can set the PYTHON env variable' },
headers:
{ 'postman-token': 'b0b78842-94cd-a0b9-39cc-0e099136900c',
'cache-control': 'no-cache',
'Accept': 'application/json' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
}`
I generated the code for the request using postman itself, I tried it on different API and the same code is working fine.
I need help in figuring out how to get JSON as response.
Here is the response:
cache-control: private content-type: application/json; charset=utf-8 content-encoding: gzip access-control-allow-origin: * access-control-allow-methods: GET, POST access-control-allow-credentials: false x-content-type-options: nosniff date: Sun, 21 Jan 2018 16:12:19 GMT connection: close content-length: 4780
Here is a sample of data returned:
���������U����"�z�f%��-??ӵm��N�|�f&��fે�n�.""��DX�Ƀ�P��J�(�p�U�Q�N47 �1�M�.�|]�t5agA��0�rc �g�3��} +�Y�q/�pL��M�RƜGwt�B��ڍ�@���9(>s��ʀ6�@�w���e/��Mu�ʮ��9,�ML| �s9�a���ߑW�r�[����ߗa�������a�~6��>ͦ����u�3���a�|P-�ᣖ�S' � �#v�D�PXM�i��ȹ��O�{2N�s��? ����ڝ���O_������/ ���ř��M3��w�ܾ����g"�� ���$�(%"�r#S�Px3��;?4^}��n�S�f7U[���g7� a�cȩbҷ�Oq����X,8w�5Szp�P�y���rg�<�������m�;�u���|��aXJ��!��~X�bK�#�b5���,)W+����)������+n[cl()�����lC> okoSHcY��c\�TW0ƊLM ��ݒ���oN9دhV���t��rj�� *�cPޝ�~l���E�́Ѳ�o3Dp�Eus侫��L��R�n��i�`+����DF���h $~377s=��W��xP��#�CAN�1�T�Ub0c$�e����S���&���B�}�~��Q�������m��m�������a�|���sL�Y;z8��T}�j~�]}���El�����]|��B�����*nt�^�,����� k' 7�J�IO�i�d�m�4"�N���DZ��1䞦'�[�&�j���~�6�).G��v=��gn��x4�6nh�����V��o�)���^ಧ�2����['6����z� �#�/���J���j+vD�xƍ)N����qC[C���U��Z|�����vh���_��>�gd�9��v���.��i�U�zJ��,�*J��RBt�s��iӮo��f�^A3��$�"7�N��!�l�b,"��96�@�������C���.��a�52'a�v�U��9��v]�l�~kΎ��ԌG�藊<9�eN;]t��n�k?;cu� L�u}�t���q;৯��=�����Y��ZK������AL.�L