簡體   English   中英

POST時HttpClient無法獲得響應

[英]HttpClient not getting response when POST

我想收到服務器的響應。 與郵遞員一起工作出色:請求:

{
    "name": "antonio",
    "username": "antonio",
    "email": "antonio@antonio.pl",
    "password": "antonio"
}

響應:

{
    "success": true,
    "message": "User was successfully registered"
}

我試圖在Angular中實現同樣的事情,所以我得到了:

  this.http.post('http://localhost:8090/api/auth/signup',
  JSON.stringify({name: name, username: username, password: password, email: email}),
  {headers: new HttpHeaders({'Content-Type': 'application/json'})})
  .subscribe(res => alert(res[0]));

檢查了后端API,效果很好,但仍然沒有出現警報。 有任何想法嗎?

如果將請求作為“ application / json”發送,則不需要JSON.stringify()。 我不知道您的后端如何解釋它。

 this.http.post('http://localhost:8090/api/auth/signup', {name: name, username: username, password: password, email: email}, {headers: new HttpHeaders({'Content-Type': 'application/json'})}) .subscribe(res => alert(res[0])); 

https://angular.io/api/common/http/HttpClient#post

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM