Cannot Send GET Request with Content-Type Header with RestSharp v107
See original GitHub issueAfter upgrading to v107, I started getting the following error when trying to execute a GET request with the Content-Type: application/force-download
header:
Cannot send a content-body with this verb-type.
The header is the only parameter in the request, but it seems like RestSharp transparently adds a body causing the error.
All attempts below causes the error mentioned when executing the request:
restRequest.AddHeader("Content-Type", "application/force-download");
restRequest.Parameters.AddParameter(new BodyParameter("", "", "application/force-download", DataFormat.None));
restRequest.AddStringBody("", "application/force-download");
While it may not be a good practice to use this header parameter with a GET request, it is unfortunately required for me to perform some operation with a system from a vendor and the last version of RestSharp does not support this anymore.
Issue Analytics
- State:
- Created 2 years ago
- Comments:18 (12 by maintainers)
@VictorRH have you read the docs following the link I posted? RestSharp adds the necessary headers automatically if the request has a body.
Here’s the code that would work:
and here is what the request looks like:
Notice that the content-type header is present, although if you use HttpTracer you won’t see it. It’s because HttpTracer does not print out content headers, it only shows you request headers.
I managed to apply a fix with a utility class using
System.Net.HttpClient
directly. The implementation might be too dirty for many, but the usage is very simple and clean: