RestSharp: remove exception from GET requests Http verb GET does not support body

Expected Behavior

i use RestSharp over Elasticsearch where most of time get request are with body but RestSharp is throwing exception when we add body with http GET requests wee need to change the request to POST please remove this problem.

Actual Behavior

Steps to Reproduce the Problem

  1. var request = new RestRequest(Method.POST); string sUrl = $“{_uri}/_search?pretty”; string body = “{ "size": 10000}”; request.AddJsonBody (body); var resetClinet = new RestClient(sUrl); var response = resetClinet.Execute(request);

Specifications

  • Version: “106.10.1”
  • Platform: .net core
  • Subsystem:

StackTrace

System.NotSupportedException: Http verb GET does not support body at RestSharp.Http.<>c__DisplayClass179_0.<GetStyleMethodInternal>b__0(HttpWebRequest r) at RestSharp.Http.ExecuteRequest(String httpMethod, Action1 prepareRequest) at RestSharp.Http.GetStyleMethodInternal(String method) at RestSharp.Http.AsGet(String httpMethod) at RestSharp.RestClient.DoExecuteAsGet(IHttp http, String method) at RestSharp.RestClient.Execute(IRestRequest request, String httpMethod, Func3 getResponse)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (4 by maintainers)

Most upvoted comments

request.AddParameter(“application/json”, “things”, ParameterType.GetOrPost);

Let me take a look.

Can u plz remove the original mail headers that I accidentally forwarded in the msg above?

I can confirm that this problem exists in the latest version (107.2.1). Sending request body parameters with a Get request throws the following exception:

Cannot send a content-body with this verb-type.

Same code works correctly in 106.11.7.

We had lots of discussions about it.

In fact, HttpWebRequest doesn’t support GET with body in a way that it just doesn’t add the body. People got burned by it often because we accept it like it’s ok and it just doesn’t being sent over.

So, now we throw until it gets supported.

Consider, that even if we remove the throw it will still not work. That is exactly the intention behind the throw.