我正在尝试从API提取数据,但是我一直都在收到错误消息
GET http://softbike.dev.myddp.eu/api/1/me/ 401 Unauthorized
{deatils: you are not authorized to see data
我也是授权承载者,但仍然出现错误,这是我的代码。
handleSubmit(e) {
e.preventDefault();
axios({
// Define Method
method: "post",
// Set Access Token URL
url: `http://softbike.dev.myddp.eu/api/1/oauth/token/`,
//Set Headers
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Accept: "application/json",
Authorization: `Bearer ${localStorage.getItem("Token")}`
// "Cache-Control": "no-cache"
},
// Interpolate variables in the strings using Template Literals
data: `grant_type=${GRANT_TYPE}&username=${this.state.username}&password=${this.state.password}&client_id=${CLIENT_ID}`
})
.then(response => {
console.log(response.data);
var ls = require("local-storage");
ls.set("Token", response.data["access_token"]);
ls.set("RefreshToken", response.data["refresh_token"]);
this.redirect();
})
.catch(response => {
//handle error
console.log(response);
});
}
在获取中,有一个我想从那里获取数据的原始链接,当我输入登录名和密码时,我可以登录并存储令牌,在本地存储中刷新令牌,但是我看不到后端数据,因为我遇到错误,因此无法解决此问题