在我的react网站上,我要生成令牌。我正在调用我的API,并且未定义响应。
[object Error]{config: Object {...}, description: "Network Error",
message: "Network Error", name: "Error", request: XMLHttpRequest {...}, response: undefined, stack: "Error: Netw..."}
这是我的反应代码。
const axios = require("axios");
const fakeAuth = {
isAuthenticated: false,
authenticate(cb: any) {
this.isAuthenticated = true;
axios.post('https://localhost:44310/api/Users/Token' )
.then((response : any) => {
console.log(response)
})
.catch((error : any) =>{
console.log(error)
})
},
signout(cb: any) {
this.isAuthenticated = false;
},
getValue() {
return this.isAuthenticated;
}
};
export default fakeAuth;
和我的API令牌方法。
private string Token()
{
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("qwertyuiopqwertyuiop"));
var signInCred = new SigningCredentials(key, SecurityAlgorithms.HmacSha256Signature);
var token = new JwtSecurityToken(
issuer: "localhost",
audience: "localhost",
expires: DateTime.Now.AddMinutes(1),
signingCredentials: signInCred
);
var tokenString = new JwtSecurityTokenHandler().WriteToken(token);
return tokenString;
}