![](/img/trans.png)
[英]How to make a Post request with “content type”: “application/x-www-form-urlencoded”?
[英]how to use the simple-oauth2 library to make request application/x-www-form-urlencoded?
我有一些代碼可以完美地通過 mac 終端工作並從網站給我令牌
curl -XPOST "https://link.com/oauth/access_token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: 1.0" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "client_id=myawesomeapp" \
--data-urlencode "client_secret=abc123" \
--data-urlencode "scope=read write"
我想在沒有 curl 請求的情況下通過 nodejs 進行請求。 網站在 npm 庫 simple-oauth2 上提供鏈接,但我的代碼不起作用。
我不工作的版本
const credentials = {
client: {
id: 'myawesomeapp',
secret: 'abc123'
},
auth: {
tokenHost: 'https://link.com',
tokenPath: '/oauth/access_token'
},
http: {
'headers.authorization': 'headers.Accept = application/x-www-form-urlencoded'
}
};
oauth2 = oauth2.create(credentials);
oauth2.accessToken.create()
如果它是 x-www-form-urlencoded 內容類型,您可能還需要更新表單選項中的授權方法(其默認值為header )。 IE
const credentials = {
/*
your existing config
*/
options: {
authorizationMethod: 'body'
}
}
希望這應該可以解決問題......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.