无法向 Pocket api 发送 http post 请求以获取请求令牌。我已经有了消费者密钥。问题似乎在于设置标头并在请求中发送数据。在浏览器中查看的请求不显示任何标题和数据。
配置请求
var req = {
method:'POST',
url:'https://getpocket.com/v3/oauth/request',
headers: { 'Content-Type': "application/x-www-form-urlencoded; charset=UTF8",
'X-Accept':'application/x-www-form-urlencoded'
},
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data: pocket_data
};
$http(req).then(function(result){console.log(result);
},function(error){
console.log(error);
});
来自浏览器的请求。我不明白为什么请求方法是 OPTIONS 而不是 POST。
Request URL:https://getpocket.com/v3/oauth/request
Request Method:OPTIONS
Status Code:400 Bad Request
Remote Address:52.0.87.91:443
已发送响应标头和请求标头。当我将其设置为 application/x-www-form-urlencoded 时,我不明白为什么内容类型是 text/html 。
**Response Headers**
view source
Cache-Control:private
Connection:keep-alive
Content-Length:15
Content-Type:text/html; charset=UTF-8
Date:Thu, 04 Feb 2016 07:22:35 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
P3P:policyref="/w3c/p3p.xml", CP="ALL CURa ADMa DEVa OUR IND UNI COM NAV INT STA PRE"
Pragma:no-cache
Server:Apache
Set-Cookie:PHPSESSID=ogqn0s0gmjpo24j6oo6rlj6vm6; path=/
Status:400 Bad Request
X-Error:Missing consumer key.
X-Error-Code:138
X-Source:Pocket
**Request Headers**
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, content-type, x-accept
Access-Control-Request-Method:POST
Cache-Control:no-cache
Connection:keep-alive
Host:getpocket.com
Origin:http://localhost:9000
Pragma:no-cache
Referer:http://localhost:9000/create
我什至尝试将 content-type 设置为 'application/json' ,但没有奏效。 口袋的 api 文档。