这就是我的代码的样子
let body = {
authCode: "XXXX",
clientId: "YYYYYY",
clientSecret: "ZZZZZZ"
};
fetch('https://api.myapp.com/oauth/token',{
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
mode: 'no-cors',
body: body
}).then(function(response){
console.log("response: ", response);
}).catch(function(error){
console.log("could not get tokens: ", error);
})
我试着这样做curl command
,这就是它的样子
➜ ~ curl -X POST -H "Content-Type: application/json" -d '{
"authCode": "XXXX",
"clientId": "YYYYY",
"clientSecret": "ZZZZZZZZ"
}' https://api.myapp.com/oauth/token
{"authToken":"e141kjhkwr3432ca9b3d2128385ad91db4cd2:cca6b151-cab4-4de2-81db-9a739a62ae88:23000000"}
我在这里做错了什么?
更新
改成follow之后,结果还是 HTTP 415
fetch('https://api.myapp.com/oauth/token',{
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
mode: 'no-cors',
body: JSON.stringify(body)
}).then(function(response){
console.log("response: ", response);
}).catch(function(error){
console.log("could not get tokens: ", error);
})
有趣的是,我意识到我发送了标头,"Content-Type": "application/json"
而我返回的是content-type: text/plain
,为什么会发生这种情况?