angular(angular6/angular7/angular8) delete請求body的問題

angular中httpclient delete請求,不接受body,只需將其放在options對象中即可

在 angular6.x ,angular7.x, angular8.x及以上版本中修改如下:

const options = {
  headers: new HttpHeaders({
    'Content-Type': 'application/json',
  }),
  body:anyObject
};

this.httpClient
  .delete('http://localhost:8080/something', options)
  .subscribe((s) => {
    console.log(s);
  });

在Angular 2.x, 4.x and 5.x中,修改如下:

http.delete('/api/something', new RequestOptions({
   headers: headers,
   body: anyObject
}))

這樣delete請求就可以攜帶body

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章