damu11782 / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

Cannot set a request body for a GET method #389

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Using rest-assured 2.4.0, one can't send GET requests with a body.

It should work but it throw saying "Cannot set a request body for a GET method".
Here an excerpt of the stacktrace:

    java.lang.IllegalArgumentException: Cannot set a request body for a GET method
        at com.jayway.restassured.internal.http.HTTPBuilder$RequestConfigDelegate.setBody(HTTPBuilder.java:1076)
        at com.jayway.restassured.internal.http.HTTPBuilder$RequestConfigDelegate.setBody(HTTPBuilder.java:1061)

HTTP do not forbid bodies on GET requests.
Some largely used products like ElasticSearch require GET requests with bodies.

Original issue reported on code.google.com by eskato...@gmail.com on 5 Mar 2015 at 4:22

GoogleCodeExporter commented 9 years ago
Then I think they're misusing the HTTP GET verb. You CAN send a body in a GET 
request but shouldn't. See for example 
http://stackoverflow.com/questions/978061/http-get-with-request-body. Even Roy 
Fielding (the inventor of REST) says this:

"So, yes, you can send a body with GET, and no, it is never useful to do so."

Original comment by johan.ha...@gmail.com on 16 Mar 2015 at 10:53

GoogleCodeExporter commented 9 years ago
Sure but as it is not forbidden, some products do it.

I think that `rest-assured`, as a testing oriented library, should allow us to 
do so.

What is forbidden is for a server to parse it and change it's behaviour based 
on its content.

Please reconsider this.

Original comment by eskato...@gmail.com on 16 Mar 2015 at 1:53

GoogleCodeExporter commented 9 years ago
I see your point and I'm not totally against this. However I don't think Apache 
HTTP Client supports this by default either (and RA builds on top of AHC) so 
this means that it'll probably be a bit hard to implement (other things that RA 
supports that AHC doesn't such as non-value parameters were quite hard to 
implement). But if you want to help out you could perhaps find out how to do 
this with Apache HTTP Client then it would be much easier for me to implement 
in RA.

Original comment by johan.ha...@gmail.com on 16 Mar 2015 at 3:54