簡體   English   中英

Angular6 http post 方法不會將數據傳遞給 web api

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

我沒有從 angular 6 應用程序接收有關 asp.net 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));
  }

不要調用JSON.stringify ,因為 Angular Http / HttpClient類會為你做這件事。 如果你自己做,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