【问题标题】:React Native getting response 400 when post to oauth/token using laravel passport使用 laravel 护照发布到 oauth/token 时,React Native 得到响应 400
【发布时间】:2017-10-25 07:07:43
【问题描述】:

我正在尝试通过我的 React Native 项目中的 oauth/tokens 登录。我已经用 POSTMAN 进行了测试,当我从 axios 发送数据时,它运行良好。但是当我尝试从我的应用程序发送时,它给了我 错误:请求失败,状态码为 400 我的代码是:

axios({
method: 'post',
url: 'http://183.172.100.84:8000/oauth/token',
headers: { 
    'Accept': 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
},
data: {
    client_id : '2',
    client_secret : 'secret',
    grant_type : 'password',
    email : this.state.userEmail,
    password : this.state.userPassword
}
})
.then((response) => {
console.log(response.data);
})

【问题讨论】:

  • 将您的 Content-Type 更改为 application\json 并重试

标签: laravel-5 react-native oauth axios laravel-passport


【解决方案1】:

我是这样解决问题的:

 axios({
method: 'post',
url: 'http://183.172.100.84:8000/oauth/token',
headers: { 
    'Accept': 'application/json',
        'Content-Type': 'application/json; charset=utf-8'
},
data: 'client_id=2&client_secret=secret&grant_type=password&email=' + this.state.userEmail+'&password='+this.state.userPassword    
})
.then((response) => {
console.log(response.data);
})

好像axios处理json格式的数据有些问题。

如果你使用 Webpack,你还必须配置代理。

【讨论】:

猜你喜欢
  • 2017-09-16
  • 2020-12-02
  • 1970-01-01
  • 2015-08-05
  • 1970-01-01
  • 2019-01-04
  • 1970-01-01
  • 1970-01-01
  • 2017-10-09
相关资源
最近更新 更多