我尝试使用cURL和**fetch(JavaScript)**调用一个API端点,因为它可以很好地与cURL一起工作,而fetch却不能。
下面是cURL请求:
curl -i -L -H 'Accept: application/json' --data 'client_id=[ID]&c
lient_secret=[SECRET]&grant_type=authorization_code&red
irect_uri=[REDIRECT_URI]&code=[CODE]' https://orcid.org/oauth/token
何处获取:
fetch("https://orcid.org/oauth/token", {
method: "POST",
headers: {
Accept: "application/json",
},
body: `client_id=[ID]&c
lient_secret=[SECRET]&grant_type=authorization_code&red
irect_uri=[REDIRECT_URI]&code=[CODE]`,
})
.then((res) => res.json())
.then((data) => {
console.log(data);
})
.catch((error) => console.log(error));
错误:
www-authenticate: Bearer realm="orcid", error="unauthorized", error_description="An Authentication object was not found in the SecurityContext"
1条答案
按热度按时间3zwtqj6y1#
我在PayU上也遇到了类似的问题。一旦我将字符串化的主体更改为
URLSearchParams
对象,我的问题就消失了。我不确定它是否对您有帮助,但您可以尝试以下代码: