[英]Pocket authentication returns BadRequest with content-type 'application/json'
I am retrieving access token for pocket api. 我正在检索Pocket API的访问令牌。 I am able to do so successfully using a Http POST request with content type as
application/x-www-form-urlencoded
. 我可以使用内容类型为
application/x-www-form-urlencoded
的Http POST请求成功完成此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
. 但是Pocket也支持内容类型为
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'
“ 400错误请求”
I am doing this on nodejs. 我在nodejs上执行此操作。 Do i have to pass any extra details on this, like 'X-Accept'(dont know how do so).
我是否需要传递任何其他详细信息,例如“ X-Accept”(不知道怎么做)。
I think Pocket is reporting a bad request because you are sending form encoded data while declaring it as JSON in Content-Type
Header. 我认为Pocket报告了一个错误的请求,因为您正在发送表单编码的数据,同时在
Content-Type
Header中将其声明为JSON。
If you want to send data to Pocket in JSON format, set Content-Type: application/json; charset=UTF8
如果要以JSON格式将数据发送到Pocket,请设置
Content-Type: application/json; charset=UTF8
Content-Type: application/json; charset=UTF8
. Content-Type: application/json; charset=UTF8
。
If you want to receive data in JSON format set X-Accept: application/json
. 如果要接收 JSON格式的数据,请设置
X-Accept: application/json
。
To include custom headers in HTTP requests, just add the name value pair to req.headers
before sending them. 要在HTTP请求中包含自定义标头,只需在发送
req.headers
前将名称值对添加到req.headers
即可。 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 . 看看https://nodejs.org/api/http.html#http_http_request_options_callback 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.