Question

There's no way to paste it in from my console, but try running the script with "node file.js ttuuu ttppp", and you'll see what I mean. It's just choking on this invalid JSON response and crashing the script when it receives that...

Link: https://gist.github.com/bmproc/bdcd926c875597e3246b

Any ideas?

Était-ce utile?

La solution

Your script specifies 'Accept-Encoding': 'gzip, deflate', so the response body is probably going to be Gzip or Deflate encoded as long as the server supports it.

Two options:

  1. You'll need to either disable that and just get the response without compression.
  2. Decompress the data by checking the Content-Encoding response header and then using zlib.gunzip or zlib.inflate. Your current code doesn't use streaming, but if it did, you would use zlib.createGunzip() or zlib.createInflate()
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top