Trash JSON Response - Node Request

I am trying to parse a JSON response using Node and Request . JSON's answer comes from Apple, so I assume this is completely fair JSON. Also, if I use Post Master for Chrome to send a request, then the original answer seems to be completely correct. I even used a sketchy packet to use the original byte response - if there is an erroneous byte in the response, everything seems good again.

However, the following code displays complete garbage for each log statement (I tried this on several machines and with different versions of Node and Request to no avail):

request(postOptions, function(error, response, body) {
    if (!error && response.statusCode == 200) {

            console.log(body);
            console.log(body.toString());
            console.log(JSON.parse(body));

    }               
});

Where postOptions:

var postOptions = {
    url: '_THE_VALID_URL_',
    followAllRedirects: true,
    method: 'POST',
    body: '_THE_VALID_BODY_',
    headers: {

        'Connection': 'keep-alive',
        'Cache-Control': 'no-cache',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36',
        'Accept': '*/*',
        'Accept-Encoding': 'gzip, deflate',
        'Accept-Language': 'en-US,en;q=0.8,pt;q=0.6',

    }
}

I made sure that all parameters are the same as those that I use when I make a POST request using the Post Master.

, :

R n1 k - V $Pr Ib _Ҕ & # {Ι Yp ފ h ~ eNKXbn | 2HDeD ^ yJB, fkuDj @PJɍpc -pOuaQIc > ^ hd0% 5 & , G # 5mYV { Coon/8b 虬 yV8 @F% Mςb\tS'M | 2                                                      o_ {ÙB #S * < {_ q ؀ 25 ؘ sSa ^ Frp qn ɾVr S% l.f 7 ڃ? 0 ɖ ( P ~ T U

-, , , , !

+4
1

@KevinB - gzipping.

gzipped-. gzip: true postOptions , !

+8

All Articles