小编And*_*edo的帖子

Angular 2 http post null Web Api Core

我正在使用现有的Web Api(ASP.NET Core)在角度2中实现一个新的Web应用程序,但我遇到了HTTP Post的问题.在搜索了所有类型的信息之后,我仍然无法解决这个问题,我的Web API仍然从角度帖子接收空参数.

我需要看看这里有什么问题.这是我的Angular 2代码:

   posted(event) {
 @Injectable()
export class httpTestComponent {

constructor(public http: Http) {

};

posted(event) {
    var user: UserViewModel = {
        name: "angularUser",
        password: "pw",
        email: "angularMail"
    }
    let pedido = JSON.stringify(user);

    let headers = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({ headers: headers });

    this.http.post('http://localhost:10832/api/Account/Register', { pedido }, options)
        .map(this.extractData).catch(this.handleError).subscribe();
};
Run Code Online (Sandbox Code Playgroud)

视图模型:

export interface UserViewModel {
name: string,
password: string,
email: string,
Run Code Online (Sandbox Code Playgroud)

}

Web API:

 [HttpPost]
    [Route("Register")]
    public void Register([FromBody] UserRegisterViewModel …
Run Code Online (Sandbox Code Playgroud)

javascript asp.net http-post asp.net-web-api angular

1
推荐指数
1
解决办法
2823
查看次数