You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular5中如何通过HttpClient Delete请求传递请求体?

Fixing Angular 5 HttpClient DELETE Request with Body

Ah, I get it—you're running into trouble because you're putting your request body in the wrong parameter. Let's break down what's wrong and how to fix it.

The Problem in Your Code

You're passing your removeFile body to the observe parameter, which is totally not what that's for. The observe parameter is meant to specify what part of the HTTP response you want to handle (like 'body' for just the response data, or 'response' for the full HTTP response object). Shoving your request body here is why you're seeing errors.

The Correct Implementation

In Angular 5's HttpClient, the DELETE method accepts the request body as part of the options object, under the body property. Here's how to adjust your code:

let body = removeFile;
return this.httpClient.delete(`${apiRoot}RemoveQueryData`, {
  headers: new HttpHeaders()
    .set('Content-Type', 'application/json')
    .set('Authorization', `Bearer ${accessToken}`),
  body: body, // This is where your request body belongs
  observe: 'body' // Use 'response' instead if you need the full HTTP response details
});

A Quick Heads-Up

While Angular supports sending a body with DELETE requests, not all backend frameworks or servers handle this by default. Double-check that your backend endpoint is configured to accept a body alongside DELETE requests if you still run into issues after fixing the frontend code.

内容的提问来源于stack exchange,提问作者siva.kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:32:55