[英]Laravel Passport works fine on PostMan, but returns 401 inside the react native app?
When I make my Axios call inside of the react native app, it returns 401. However, when I grab the parsed header inside of the Network tab it shows:当我在 react native 应用程序内部进行 Axios 调用时,它返回 401。但是,当我在 Network 选项卡内获取已解析的 header 时,它显示:
const config = {
method: "POST",
baseURL: API_URL,
data:request_data,
headers: {
'Authorization' : 'Bearer '+ token
}
}
let data = await axios('user_update_profile',config)
console.log(data) //return 401 Unauthorized Error
Any idea how to fix this?知道如何解决这个问题吗? I am using Laravel version 6
我正在使用 Laravel 版本 6
The correct way to set headers in Axios Wrong-way:在 Axios 中设置标头的正确方法 错误方式:
const config = {
method: "POST",
baseURL: API_URL,
data:request_data,
headers: {
'Authorization' : 'Bearer '+ token
}
}
let data = await axios('user_update_profile',config)
So the Correct way is所以正确的方法是
let data = await axios.post(API_URL+'user_update_profile',request_data,{
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer '+token
}
})
// console.log('----cheers---------',data)
dispatch(userUpdateProfileSuccess(data))
Thanks谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.