I want to add a body to my delete http request but it seems that the http pakage doesnt accept it
http.delete('${config.basicUrl}removeFavorite', body: json.encode(requestBody))
is there any solution for this ?
While it is not explicitly forbidden to include a body with a DELETE request, most HTTP servers do not support it.
To send a request body with an Axios DELETE request, you should set the data option. Remember that the 2nd parameter to axios. delete() is the Axios options, not the request body. You can't pass the request body as the 2nd parameter like you can with axios.
You can send payload along with the DELETE request as part of the params in the options object as follows: this. http. delete('http://testAPI:3000/stuff', { params: { data: yourData }).
final client = http.Client();
try {
final response = await client.send(
http.Request("DELETE", Uri.parse("${config.basicUrl}removeFavorite"))
..headers["authorization"] = "Bearer $bearer"
..body = "...");
//
} finally {
client.close();
}
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