gpt4 book ai didi

javascript - react Native JWT-auth Error fetching api

转载 作者:行者123 更新时间:2023-12-03 16:45:07 26 4
gpt4 key购买 nike

React Native JWT-auth Error fetching api

我正在尝试通过以下方法使用 jwt-auth 获取用户详细信息。

login() {
alert(this.state.UserName);
fetch (Api+''+'/wp-json/jwt-auth/v1/token',{
method: "POST",
username: this.state.UserName,
password: this.state.Password
}).then((response) => response.json())
.then((responseData) =>{
console.log("LoginData:-" + JSON.stringify(responseData));
}).done();
}
}

并得到错误: -
{
"code":"[jwt_auth] empty_username",
"message":"<strong>ERROR</strong>: The username field is empty.",
"data":{"status":403}
}

如果有人知道请帮忙。

最佳答案

我认为您不再需要答案了,因为发布这个问题已经有一年了,如果还有其他人需要

networking所示React Native 的 tab 你需要通过 数据进入正文 header 中的 JWT token 如下所示,这对我有用,所以如果有任何问题,请查看并更新

login(){
fetch(Api+''+'/wp-json/jwt-auth/v1/token', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'JWT '+<token> // There will be different type of authorization like Bearer, JWT, Basic
},
body: JSON.stringify({
username: this.state.UserName,
password: this.state.Password
}),
})
.then((response) => response.json())
.then((responseData) => {
console.log("LoginData:-" + JSON.stringify(responseData));
}).done();
}

关于javascript - react Native JWT-auth Error fetching api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46157487/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com