0

So I'm doing the request:

curl -i https://one.nhtsa.gov/webapi/api/SafetyRatings/modelyear/undefined/make/Ford/model/Fusion\?format\=json

HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
SSL-TLS: TLSv1.2
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 163
Date: Mon, 04 Jun 2018 00:31:15 GMT
Connection: keep-alive
Set-Cookie: NHTSA=2585027594.20480.0000; path=/; Httponly; Secure
Set-Cookie: NHTSA=3323225098.47873.0000; path=/; Httponly; Secure
Strict-Transport-Security: max-age=31536000

-....

This response with and 400 error using Content-Encoding: gzip. I'm doing this with javascript/node, also request-promise but still not sure how to "uncompress' its message.

var rp = require('request-promise');

function getVehicles(year, manufacturer, model) {
  var options = {
    uri: `https://one.nhtsa.gov/webapi/api/SafetyRatings/modelyear/${year}/make/${manufacturer}/model/${model}`,
    qs: {
      format: 'json'
    },
    json: true
  };

  return rp(options);
}
learnercys
  • 302
  • 1
  • 3
  • 16
  • https://stackoverflow.com/questions/8880741/node-js-easy-http-requests-with-gzip-deflate-compression ? – gman Jun 04 '18 at 02:32
  • 1
    You probably really want to `pipe()` since if it's large enough to `gzip` then you probably want the stream instead. If you really want to persist with a promise implementation the [`mz`](https://github.com/normalize/mz) library wraps standard NodeJS libraries with promise implementations – Neil Lunn Jun 04 '18 at 02:33
  • Thanks, it's duplicated, I just was missing where the body was and to set the encoding. – learnercys Jun 04 '18 at 04:35

0 Answers0