javascript - 在 react-native 中使用 axios 生成访问令牌
问题描述
我想在 react-native 中执行相同的过程,并且我已经尝试过
var baseHeaders = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer ' + btoa(client_id + ':' + client_secret)
};
var params = {
client_id: client_id,
client_secret: client_secret,
grant_type: "client_credentials",
}
axios({
method: 'POST',
url: "http://transrv02-ap01.transsyssolutions.com:8080/apex/apxprd/oauth/token",
headers: baseHeaders,
body:params
})
.then((responseJson) => { console.log("clientid---"+responseJson)})
.catch((error) => {
console.error(error);
});
但它显示401错误。任何人都可以帮助我!提前致谢....
解决方案
你可以试试这个...
axios.post('http://transrv02-ap01.transsyssolutions.com:8080/apex/apxprd/oauth/token',
params,
{
headers: baseHeaders
})
.then((responseJson) => { console.log("clientid---"+responseJson)})
.catch((error) => {
console.error(error);
});
推荐阅读
- python - 如何在后台调度 Python Selenium 脚本?
- httpclient - RestSharp 到 HTTPClient RequestBody
- hibernate-tools - HibernateTools hbm2ddl ant 任务不保留顺序
- javascript - 使用条件语句过滤对象数组
- sql - Sybase SQL:分区上的行号
- javascript - 在 Javascript 中访问对象的对象
- database - 如何修复安装 mongoDB
- nginx - 如何在带有 nginx 的 debian 9 服务器上通过 https 从 phpmyadmin 发送数据?
- c# - Xamarin iOS - 使用 XCode 编辑的 .xib 的 .cs 和 .designer.cs 文件
- wordpress - 自动将新的 Wordpress 用户添加到 NinjaTables Pro