【发布时间】:2017-09-23 14:21:40
【问题描述】:
在 Angular 中使用如下调用:
function Login(email, password, callback)
{
var GetAll = new Object();
GetAll.email = email;
GetAll.password = email;
$http({
url: "http://localhost:52587/api/TokenAuth/Login",
dataType: 'json',
method: 'post',
data: JSON.stringify(GetAll),
headers: {
'Content-Type': 'application/json'
}
})
.then(function loginSuccessCallback(response)
{...
我已经使用 swagger 和 ajax 对此进行了测试,效果很好。我在正文中使用 json 对象设置它(设置为 raw 和 JSON (application/json))。
我编写了以下 Web API:
namespace WEBAPI.Controllers
{
public class user
{
public string email { get; set; }
public string password { get; set; }
}
[Produces("application/json")]
[Route("api/[controller]")]
public class TokenAuthController : Controller
{
[HttpPost("Login")]
public async Task`<IActionResult>` Login([FromBody]user usr)
{
..................
..................
}
}
}
但我收到 [FromBody] 415 unsupported media type 和
没有 [FromBody] 获得空参数。请帮帮我
有人知道我哪里出错了吗?
【问题讨论】:
标签: c# angularjs asp.net-mvc asp.net-web-api asp.net-core-webapi