简体   繁体   English

Angular6 http post 方法不会将数据传递给 web api

[英]Angular6 http post method does not pass data to web api

i am not receiving data on asp.net mvc core api from angular 6 app.我没有从 angular 6 应用程序接收有关 asp.net mvc core api 的数据。 Image is here MVC core api图像在这里MVC 核心 api

httpOptions = {
    headers: new HttpHeaders({
      'Content-Type': 'application/json'
    })
  };  

  createUser(user: User): Observable<any> {;
    let body = JSON.stringify(user);
    return this.http.post<any>('http://localhost:51001/api/User/' + "PostUser", body, this.httpOptions)
      .pipe(catchError(this.handleError));
  }

Don't call JSON.stringify , as the Angular Http / HttpClient class will do this for you.不要调用JSON.stringify ,因为 Angular Http / HttpClient类会为你做这件事。 If you do it yourself, Angular will then call stringify on the string, which is causing the problem you're seeing.如果你自己做,Angular 会在stringify上调用stringify ,这会导致你看到的问题。

  createUser(user: User): Observable<any> {;
    return this.http.post<any>('http://localhost:51001/api/User/' + "PostUser", user, this.httpOptions)
      .pipe(catchError(this.handleError));
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM