【发布时间】:2018-11-07 13:04:19
【问题描述】:
我正在尝试从 Angular 客户端向 C# Web API 2 RESTful Web 服务发送 http post 请求。
我的客户:
var userId = "123456";
var password = "654321";
const headersContent = new Headers().set('Content-Type', 'application/x-www-form-urlencoded');
var url = "http://localhost:35615/login"
this.http.post(url, {
"userId": userId,
"password": password
}, {withCredentials: true}).subscribe(res => {
console.log(res);
});
我的服务器:
[Route("login")]
[HttpPost]
public IHttpActionResult LoginReq([FromBody] string parameters)
{
//Deserialize the parameters.
}
我的问题是参数 var 为空,尽管 chrome 中网络选项卡中的发布请求包含数据。
谁能解释我做错了什么以及如何解决它? 谢谢!
【问题讨论】:
标签: c# angular rest http asp.net-web-api2