Shouldn't it be headers
instead of header
?
http://nodejs.org/api/http.html#http_http_request_options_callback
Question
I am using request
module for Nodejs to make http request, but there is an issue with headers
object: the value cannot contain double quote otherwise it will be treated differently.
Basically I'm calling an API which requiring headers
to carry a property "X-Accesstoken".
My code:
var userId = "123";
var url = "/users/{id}".replace("{id}", userId) ;
var token = "abcd1234"; //changed to protect the innocence, anyway it'll be the valid generated token
var options = {
method: 'GET',
url: url,
header: {
"x-Accesstoken": token
"Content-Type": "application/json"
}
};
console.log('testing ' + url);
request(options, function(error,response,body){
console.log('body:' + body);
});
I always got this error:
body:'{
"status": 403,
"code": 0,
"reason": "Not authenticated"
}
Then if I use the Chrome Advanced REST API client, I realize the problem is because of the double quote (") in the X-Accesstoken
inside headers
How do I send request headers without double quotes in this case ?
Updates:
The header
typo is the root cause, not the double quote or uppercase "X-Accesstoken". When I used Advanced REST Client to send request, it sent the double quote as part of the headers value, thus render my token to be invalid.
Solution
Shouldn't it be headers
instead of header
?
http://nodejs.org/api/http.html#http_http_request_options_callback