New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scrambles text when using HTTPS module #1029
Comments
Try: res.on('data', d => data += String(d));
res.on('end', () => console.log(data)); |
@ORESoftware Your approach doesn't work. Notice that |
@ORESoftware Stringifying each chunk is usually not a good idea, it doesn’t work if multi-byte characters are split between data chunk boundaries. You should rather call @jyzykunyv What appears to be happening here is that the StackOverflow API always sends its content gzip-encoded, regardless of whether the client allowed that or not. This code works: 'use strict';
var https = require('https');
var zlib = require('zlib');
var stackExchangeURL = 'https://api.stackexchange.com/2.2/search/advanced?page=1&pagesize=100&order=asc&sort=creation&tagged=proof-theory&site=math&filter=!)r7Ynn1jCTHT*WYR)671';
https.get(stackExchangeURL, res => {
var data = '';
var body = res.pipe(zlib.createGunzip());
body.setEncoding('utf8');
body.on('data', d => data += d);
body.on('end', () => console.log(data));
}); In a real-world application, you would probably want to check
|
@addaleax Works perfectly. Many thanks! |
��z��������w5��P�)������ ������[(�m,������Ɯ�o��RS�[ �\X��[�]����YV���ݒ����J�������RL\���U����S���LSRޓ����M�YPV��M��Ԋ�\ ��Q������Z���M��Q�NZܛ��[�YX�Ob� +r�m��߀wަ� x%� |
im trying to use https module with Stack Exchange API but im getting scrambled text instead of json data here is my code
expected is to get normal data, like json data or something similar, but instead i got following scrambled text
what am i doing wrong? i tried to open url in browser and it works fine, i got valid json, but imn node it dont work why
thank in advance
The text was updated successfully, but these errors were encountered: