Friday, 26 May 2017

How to read / parse response in Node.js?

I have a websocket client, which is based on ws module.

It works on test servers, however when I'm trying to connect to a certain website it returns 301 redirect.

The module is unable to handle 301 status and throws an error.

In the source code the error message prints res.statusCode that shows 301.

What I'm trying to do is to find that new address and adjust my host.

The problem is I can't make sense of that response object.

I have tried to log it with JSON.stringify(res) but it throws an exception.

I've also tried to log res.headers, it shows this, but I can't see the new address:

Error: {"date":"Fri, 26 May 2017 22:59:10 GMT","transfer-encoding":"chunked",
"connection":"keep-alive","cache-control":"max-age=3600",
"expires":"Fri, 26 May 201 7 23:59:10 GMT",
"location":"https://this-is-the-host-im-trying-to-connect-to/",
"server":"cloudflare-nginx","cf-ray":"123467890-MNL"}



via Anonymous

No comments:

Post a Comment