我试图使用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创建表单数据时,我是否做错了什么?
发布于 2022-09-07 07:25:14
将curl命令粘贴到https://curlconverter.com/node-axios/中,并将其转换为
const axios = require('axios');
const response = await axios.post(
'https://api-sandbox.capitalone.com/oauth2/token',
new URLSearchParams({
'client_id': 'YOUR_CLIENT_ID',
'client_secret': 'YOUR_CLIENT_SECRET',
'grant_type': 'refresh_token',
'refresh_token': 'REFRESH_TOKEN_FROM_ACCESS_TOKEN_RESPONSE'
}),
{
headers: {
'Accept': 'application/json'
}
}
);
发布于 2022-04-20 09:59:44
https://stackoverflow.com/questions/71937634
复制相似问题