首页 > 解决方案 > 在 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错误。任何人都可以帮助我!提前致谢....

标签: javascriptreact-native

解决方案


你可以试试这个...

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);
  });

推荐阅读