Restsharp: Add body to Get Request (AddJsonBody) is not working

Created on 5 Jul 2019  ·  5Comments  ·  Source: restsharp/RestSharp

Expected Behavior

Valid response

Actual Behavior

Not adding any parameter or body
In VS debug mode,
I can see the parameters in req.
But the server didn't receive any body.
and I always have the error message "request body invalid or not set"

Most helpful comment

I actually think that should be considered wrong as the current version of the RFC does not explicitly deny a GET request containing a Body.

A payload within a GET request message has no defined semantics;
sending a payload body on a GET request might cause some existing
implementations to reject the request.

Seems that should be up to the server's implementation to reject it or not.

Blocking it at the client library level invalidates the use of RestSharp in many applications that, at some point, needs to communicate with someone else's server and might face this scenario.
Working around it would require implementing the use of another library.

All 5 comments

It is because according to RFCs body is not something that GET requests support.

Here is the background for it. We have no plan to do anything that is not in the RFC scope
https://stackoverflow.com/questions/978061/http-get-with-request-body

@alexeyzimarev
Thanks for your Replay!

Hi @alexeyzimarev,

I've been bumping into this recently. .Net Core now supports sending GET with bodies, although it's still not clear that this should generally be used, I see a few large APIs use it. Some use it with POST available as an alternative, but I've come across some that do not.

Reference from SO: https://stackoverflow.com/questions/43421126/possible-for-httpclient-to-send-content-or-body-for-get-request/

Of course if would be nice if everyone would get along and follow standards the same way hehe but from a "client developper" point of view. I'm stuck with needing to integrate APIs that for me to use GET with bodies.

This means that I'll have to bypass RestSharp and implement this on my own (which is way less fun).

With .net Core supporting this and APIs adopting this, could you reconsider putting this in?

Reading about this, the RFC has been modified (I think), meaning that the GET Body is supported and allowed, just that servers should ignore it.

Thanks!

I actually think that should be considered wrong as the current version of the RFC does not explicitly deny a GET request containing a Body.

A payload within a GET request message has no defined semantics;
sending a payload body on a GET request might cause some existing
implementations to reject the request.

Seems that should be up to the server's implementation to reject it or not.

Blocking it at the client library level invalidates the use of RestSharp in many applications that, at some point, needs to communicate with someone else's server and might face this scenario.
Working around it would require implementing the use of another library.

Was this page helpful?
0 / 5 - 0 ratings