[英]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.