【发布时间】:2013-08-24 23:55:32
【问题描述】:
遗憾的是,我无法使用 WebAPI 获得最基本的东西
$.ajax({
url: "https://192.168.1.100/Api/Authentication/LogIn",
type: "POST",
contentType: "application/json",
data: "{ 'username': 'admin', 'password': 'MyPass' }",
error: function (r, s, e) { alert(e); },
success: function (d, s, r) { alert(s); }
});
我得到“未找到”
API 控制器定义
public class AuthenticationController : ApiController
{
[HttpPost]
public bool LogIn(string username, string password)
{
return true;
}
}
如果我删除 HttpPost 并用 HttpGet 替换它,然后这样做
$.ajax({
url: "https://192.168.1.100/Api/Authentication/LogIn?username=admin&password=MyPass",
type: "GET",
error: function (r, s, e) { alert(e); },
success: function (d, s, r) { alert(s); }
});
效果很好。
WebAPI 出了什么问题?
【问题讨论】:
-
试试
data: "{ username: 'admin', password: 'MyPass' }"-
标签: asp.net-mvc asp.net-mvc-4 asp.net-web-api