Why do HttpMethod
s such as GET
and DELETE
cannot contain body?
public Task<HttpResponseMessage> GetAsync(Uri requestUri);
public Task<HttpResponseMessage> DeleteAsync(string requestUri);
also in Fiddler, if I supply a body, the background turns red. But still it will execute with body on it.
So as an alternative, I used SendAsync()
because it accepts HttpRequestMessage
which can contain HttpMethod
as well as the content.
// other codes
Category category = new Category(){ Description = "something" };
string categoryContent = JsonConvert.SerializeObject(category);
string type = "application/json";
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Delete, "-page-")
HttpContent content = new StringContent(categoryContent, Encoding.UTF8, type);
HttpClient client = new HttpClient();
message.Content = content;
await client.SendAsync(message, HttpCompletionOption.ResponseHeadersRead);
// other codes
Did I missed something else?
According to Mozilla a DELETE request "may" have a body, compared to a PUT, which should have a body. By this it seems optional whether you want to provide a body for a DELETE request.
Sending a message body on a DELETE request might cause some servers to reject the request. But you still can send data to the server using URL parameters. This is usually an ID of the resource you want to delete.
The short answer is: You should include a response body with an entity describing the deleted item/resource if you return 200.
Per HTTP standards, GET method is aimed to retrieve data, hence there is no need to provide a request body.
Adding a request body violates the rules defined. This is therefore prohibited.
The same applies to DELETE method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With