C# APS net MVC模型和使用HTTPS的Axios Post呼叫
我在使用axios管理POST请求时遇到一些问题。 在客户端:C# APS net MVC模型和使用HTTPS的Axios Post呼叫,c#,asp.net,post,model-view-controller,axios,C#,Asp.net,Post,Model View Controller,Axios,我在使用axios管理POST请求时遇到一些问题。 在客户端: function login() { var obj = { nome: 'admin', password: 'password'}; axios .post('https://cliapp.azurewebsites.net/api/APICalls/Login', obj) .then(function (response) { // response
function login() {
var obj = { nome: 'admin', password: 'password'};
axios
.post('https://cliapp.azurewebsites.net/api/APICalls/Login', obj)
.then(function (response) {
// response.data is an object:
// - response.data.ID
// - response.data.admin
// - response.data.authLevel
// - response.data.expirationDays})
.catch(function (err) {
alert(err)
});
}
function selectChir() {
// define data object
var obj = { unitOp: 1, chir: 1, user: 1};
axios
.post('https://cliapp.azurewebsites.net/api/APICalls/GetNumInt', obj)
.then(function (response) {
// response.data contains two parameters: ID_1 and ID_2
})
.catch(function (err) {
alert(err)
});
}
在服务器端:
[RequireHttps]
public Utente Login(LoggingUser user)
{
bool exists = CheckCredentials(user);
if (exists)
{
return new ExistingUser
{
ID = data.ID,
admin = data.admin,
authLevel = data.authLevel,
expirationDays = data.passwordExpire
};
} else
return null;
}
[RequireHttps]
public ObjectID GetNumInt(Inter obj)
{
ObjectID objectID = ExecuteWorkOn(obj.unitOp, obj.chir, obj.user)
return objectID;
}
上面的代码工作得很好
尽管有类似的情况,但下面给出了“错误:请求失败,状态代码为405”
客户端:
function login() {
var obj = { nome: 'admin', password: 'password'};
axios
.post('https://cliapp.azurewebsites.net/api/APICalls/Login', obj)
.then(function (response) {
// response.data is an object:
// - response.data.ID
// - response.data.admin
// - response.data.authLevel
// - response.data.expirationDays})
.catch(function (err) {
alert(err)
});
}
function selectChir() {
// define data object
var obj = { unitOp: 1, chir: 1, user: 1};
axios
.post('https://cliapp.azurewebsites.net/api/APICalls/GetNumInt', obj)
.then(function (response) {
// response.data contains two parameters: ID_1 and ID_2
})
.catch(function (err) {
alert(err)
});
}
服务器端:
[RequireHttps]
public Utente Login(LoggingUser user)
{
bool exists = CheckCredentials(user);
if (exists)
{
return new ExistingUser
{
ID = data.ID,
admin = data.admin,
authLevel = data.authLevel,
expirationDays = data.passwordExpire
};
} else
return null;
}
[RequireHttps]
public ObjectID GetNumInt(Inter obj)
{
ObjectID objectID = ExecuteWorkOn(obj.unitOp, obj.chir, obj.user)
return objectID;
}
405错误为“不允许使用方法”-这表明服务器端未设置HTTP Post。这可能是由于Azure配置或控制器,您可以提供控制器吗?您还尝试过通过邮递员运行API请求吗?