我正在嘗試使用 axios 模仿以下請求:
curl -i -k --tlsv1.2 -H "Accept:application/json" -H "Content-Type:application/x-www-form-urlencoded" -d "client_id=YOUR_CLIENT_ID" -d "client_secret=YOUR_CLIENT_SECRET" -d "grant_type=refresh_token" -d "refresh_token=REFRESH_TOKEN_FROM_ACCESS_TOKEN_RESPONSE" -X POST https://api-sandbox.capitalone.com/oauth2/token
更多資訊:https ://developer.capitalone.com/documentation/o-auth
我想出了以下代碼:
axios({method: ‘post’, url: ‘https://api-sandbox.capitalone.com/oauth2/token’, params: {client_id: ‘…’, client_secret: ‘…’, grant_type: ‘refresh_token’, refresh_token: ‘…’}, headers: {‘Content-Type’: ‘aplication/x-www-form-urlencoded’, Accept: ‘application/json’ }}).then(res => console.log(res)).catch(ex => console.log(ex))
這一直超時并且沒有給我任何回應,這使我相信我的請求格式不正確。嘗試使用 axios 使用表單資料創建此請求時,我做錯了什么嗎?
uj5u.com熱心網友回復:
請參閱檔案:
params是與請求一起發送的 URL 引數
要在正文中發送資料,請使用body, notparams并將其傳遞給URLSearchParams 物件,而不是普通物件。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/458865.html
標籤:javascript 卷曲 axios 要求 表单数据
