我有一个请求curl
,我已转换为node-fetch
请求。我相信一切都是平等的,但我收到以下错误:
{
"error_index": [...],
"error_description":"The Content-Type is not supported by the authorization server",
"error":"invalid_request"
}
标题看起来和我一模一样,所以我想弄清楚还有什么可能导致这个问题。这是调用curl
:
curl -sS \
-X POST \
-H "ContentType:application/x-www-form-urlencoded;charset=UTF-8" \
--data-urlencode "grant_type=refresh_token" \
--data-urlencode "client_id=$CLIENT_ID" \
--data-urlencode "client_secret=$CLIENT_SECRET" \
--data-urlencode "refresh_token=$REFRESH_TOKEN" \
--output $OUTPUT_FILE \
https://api.amazon.co.uk/auth/o2/token
这是 中的等价物node-fetch
:
const bodyParams = [
`grant_type=refresh_token`,
`client_id=${API_CLIENT_ID}`,
`client_secret=${API_CLIENT_SECRET}`,
`refresh_token=${token.refreshToken}`
]
const bodyString = bodyParams.join('&')
const response = await fetch('https://api.amazon.co.uk/auth/o2/token', {
method: 'POST',
headers: {
'ContentType': 'application/x-www-form-urlencoded;charset=UTF-8'
},
body: bodyString
});
版本:
curl 7.71.1
node-fetch: 2.6.6
node v16.11.1