0

The API I am tasked with consuming requests a "Content-Type" with value "application/json" along with method/verb "GET". When I attempt using Flurl, I get response "ProtocolViolationException: Cannot send a content-body with this verb-type.".

Is there a way to do this? I was also trying with HttpClient (see related SO post). (btw.. using .NET Framework 4.5).

Adam Cox
  • 3,341
  • 1
  • 36
  • 46
  • 2
    Shouldn't it be "Accept" header instead of "Content-Type" header? – John Hpa Sep 04 '19 at 04:29
  • Does the API require that you send a request _body_ on a GET request? That's unusual and not supported by HttpClient on full framework by default, but can be worked around. Can you post your code that makes the call? – Todd Menier Sep 04 '19 at 14:56
  • I am going to take a look again. What is happening is same code for net core doesnt succeed in net framework 45 proj. The lib versions are different but I cant figure what specifically is causing the failure. I think the content-type is a red herring.. – Adam Cox Sep 05 '19 at 16:55
  • 2
    @ToddMenier, you are right about this being unusual. I also have a similar case where API I am consuming enforcing Content-Type Header for a GET call. I am using Flurl and notice that Content-Type is not being sent across to API end point when it is a GET call regardless I add it explicitly in request headers. Is there a way to ensure Content-Type pass through Flurl for a GET request. Appreciate your thoughts on it. thanks – codepen Jun 11 '21 at 18:08

1 Answers1

0

The reason why in you've got this exception is that the Content-Type header is meant to be used for the POST/PUT request payloads.

From MDN:

The Content-Type entity header is used to indicate the media type of the resource.

HTTP GET method has no payload, and there is no sense to have Content-Type in the request.

In Furl, if you use Content-Type: application/json with POST or PUT, make sure to provide actual payload: null is not an option.

Milen Stefanov
  • 180
  • 1
  • 2
  • 10