Reputation: 9649
I am retrieving access token for pocket api. I am able to do so successfully using a Http POST request with content type as application/x-www-form-urlencoded
.
{
host: 'getpocket.com',
path: '/v3/oauth/authorize',
port: 443,
method: 'POST',
headers:
{ 'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': 79 }
}
But pocket also supports content type as application/json
.
{
host: 'getpocket.com',
path: '/v3/oauth/authorize',
port: 443,
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Content-Length': 79 }
}
But using this type of request returns me
'400 Bad Request'
I am doing this on nodejs. Do i have to pass any extra details on this, like 'X-Accept'(dont know how do so).
Upvotes: 0
Views: 243
Reputation: 2881
I think Pocket is reporting a bad request because you are sending form encoded data while declaring it as JSON in Content-Type
Header.
If you want to send data to Pocket in JSON format, set Content-Type: application/json; charset=UTF8
.
If you want to receive data in JSON format set X-Accept: application/json
.
To include custom headers in HTTP requests, just add the name value pair to req.headers
before sending them. For example:
headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'X-Accept' : 'application/json'}
or:
req.headers['X-Accept'] = 'application/json'
Have a look at https://nodejs.org/api/http.html#http_http_request_options_callback.
Upvotes: 1