【发布时间】:2018-04-18 11:24:58
【问题描述】:
我在 vuejs 中有这个使用 axios
axios({
method: 'post',
url: 'http://localhost:64427/api/Authenticate/Token',
headers: {
'Content-type': 'application/json'
},
data: {
quad: this.quad,
password: this.password
}
})
.then(response => {
console.log(response.header.token);
})
当我在邮递员中使用端点发帖时,它可以工作
http://localhost:64427/api/Authenticate/Token?quad=YGOP&password=P@ssw0rd
但是当我使用 axios 发布时,我可以 404 错误代码。
这里是后台
[HttpPost]
[ActionName("Token")]
[BasicAuthentication]
public HttpResponseMessage Login(string quad, string password)
{
bool isAuthenticated = EmployeeSecurity.Login(quad, password);
if(isAuthenticated)
{
if (Thread.CurrentPrincipal != null && Thread.CurrentPrincipal.Identity.IsAuthenticated)
{
var basicAuthenticationIdentity = Thread.CurrentPrincipal.Identity;
if (basicAuthenticationIdentity != null)
{
var username = basicAuthenticationIdentity.Name;
return GetAuthToken(username);
}
return null;
}
}
return null;
}
【问题讨论】:
-
您通过 Postman 访问的 URL 在 URL 参数中有数据,但另一个在正文中有数据。您能否分享您的 API 操作代码以获取更多详细信息?
-
你似乎通过邮递员使用方法“GET”,通过 axios 使用“POST”
-
@csblo 你可以在 post 方法中使用查询参数
-
@mast3rd3mon 是的,正因为如此,我没有将其作为答案发送:)
-
@csblo 都设置为 POST
标签: asp.net-web-api vue.js vuejs2 axios