node-rest-client icon indicating copy to clipboard operation
node-rest-client copied to clipboard

How to get HTTP status code

Open fvisticot opened this issue 8 years ago • 2 comments

I need to get the status code in the answer. How can I retrieve this value ? (200 OK, 401...)

fvisticot avatar Nov 05 '17 19:11 fvisticot

Hi I was able to doit with response.statusCode. It gives me the code of response object.

`var req = client.post("http://XXXXXXXXXXX", args, function (data, response) { console.log(data); // raw response console.log(typeof response); console.log(response.statusCode); /* for(var propertyName in response) { // you can get the value like this: myObject[propertyName] console.log(propertyName); } */

    });`

alejandrotamayo avatar Jan 18 '18 15:01 alejandrotamayo

@fvisticot This is the correct answer, so you should close the ticket.

inthegarage avatar Jun 15 '21 11:06 inthegarage