Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upIs POST really require body? #751
Comments
pepyakin
changed the title
Is POST a really require body?
Is POST really require body?
Apr 22, 2014
swankjesse
added
the
bug
label
May 4, 2014
swankjesse
added this to the 2.0 milestone
May 4, 2014
This comment has been minimized.
This comment has been minimized.
|
We might fix this with code or by making it foolishly easy to get an empty post body. |
This comment has been minimized.
This comment has been minimized.
|
Incidentally @Test public void postZeroLength() throws Exception {
server.enqueue(new MockResponse().setBody("abc"));
server.play();
Request request = new Request.Builder()
.url(server.getUrl("/"))
.method("POST", null)
.build();
executeSynchronously(request)
.assertCode(200)
.assertBody("abc");
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("POST", recordedRequest.getMethod());
assertEquals(0, recordedRequest.getBody().length);
assertEquals("0", recordedRequest.getHeader("Content-Length"));
assertEquals(null, recordedRequest.getHeader("Content-Type"));
} |
This comment has been minimized.
This comment has been minimized.
|
closing for now, as I think this is no longer current. |
adriancole
closed this
May 5, 2014
referenced
this issue
Apr 21, 2015
This comment has been minimized.
This comment has been minimized.
1zaman
commented
May 22, 2015
|
This is still an issue in 2.4.0 RC. |
This comment has been minimized.
This comment has been minimized.
|
@1zaman can you provide a 0-length body? I don't want to conflate null with empty. |
This comment has been minimized.
This comment has been minimized.
1zaman
commented
May 22, 2015
|
@swankjesse: This update breaks my existing application which uses Volley and OkHttp, so I'm just reverting it for now. If you mean to enforce a body in POST requests, then this should be documented as a breaking change. |
This comment has been minimized.
This comment has been minimized.
SleeplessByte
commented
May 27, 2015
|
It is trivial to provide a zero length body with Retrofit; For anyone getting here with retrofit, you can use the public interface MyService {
@POST( "yourpath") R call( @Body String body )
}
myServiceInstance.call( "" ); |
This comment has been minimized.
This comment has been minimized.
|
I would call that pretty trivial actually. On Tue, May 26, 2015 at 5:32 PM Derk-Jan Karrenbeld <
|
This comment has been minimized.
This comment has been minimized.
SleeplessByte
commented
May 27, 2015
|
Yeah; I wrote not hard and forgot to replace the not. |
This comment has been minimized.
This comment has been minimized.
beshkenadze
commented
May 27, 2015
|
@JakeWharton This is a crutch. If the server does not expect a parameter, it should not be. |
This comment has been minimized.
This comment has been minimized.
|
The RFC for HTTP requires it and you are using an OkHttp that is newer by On Wed, May 27, 2015, 1:14 AM Aleksandr Beshkenadze <
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
SleeplessByte
commented
May 27, 2015
|
The fact that servers accept non RFC requests is nothing new; I think explicitly sending an empty body isn't bad. |
This comment has been minimized.
This comment has been minimized.
|
I agree but empty is not the same as absent. Empty is allowed and not the On Wed, May 27, 2015, 1:44 AM Derk-Jan Karrenbeld notifications@github.com
|
This comment has been minimized.
This comment has been minimized.
SleeplessByte
commented
May 27, 2015
|
Can the default behaviour not be to empty an absent POST body? Convention over configuration wise? |
This comment has been minimized.
This comment has been minimized.
|
That's not what that phrase means. A POST per the HTTP spec needs the body. On Wed, May 27, 2015, 6:58 PM Derk-Jan Karrenbeld notifications@github.com
|
This comment has been minimized.
This comment has been minimized.
SleeplessByte
commented
May 31, 2015
|
Yes, I understood that. So give it (in okhttp) an empty one if none was given, instead of raising an exception? I think it's good to require the body and raise the exception, but since it is a breaking change now, one could make it deprecated yadayadayada -- |
ajwhite
referenced this issue
Oct 14, 2015
Closed
[Network] Android throws up a redbox when POST has no body #3371
This comment has been minimized.
This comment has been minimized.
slomo
commented
Nov 13, 2015
|
Where from the HTTP standard is it obvious that POST requires a body? As I see it RFC7320 says on page 27:
And later on on page 32 it specifies:
I couldn't find an restrictions for any request type/verb. |
This comment has been minimized.
This comment has been minimized.
ExplodingCabbage
commented
Dec 13, 2015
|
@slomo The best argument I can see for POSTs requiring a body comes not from RFC 7320 but from RFC 7231, where the POST method is defined. From the start of section 4.3.3:
(Emphasis is mine.) From all the prior discussion of "representations" and representations being "enclosed" in request payloads earlier in the RFC, it is reasonable to infer that "the representation enclosed in the request" refers to its body. So we have language in the definition of POST that seems to take for granted (but doesn't explicitly state) that a POST request must contain an "enclosed representation", and a whole bunch of earlier remarks in the document that seem to take for granted (but don't explicitly state) that "representations" are always things that exist in the body of a request or response. Pretty unsatisfying! Meanwhile, back in RFC 7230, there's this snippet:
Here there's an explicit distinction being made between methods like POST that define a meaning for the payload body, and others, like GET, that do not. In the former case, we're invited to think of sending request with no body as sending an "empty" body, and in the latter case we're invited to think of it as sending "no" body. Of course, as far as bytes over the wire goes an "empty" body and "no" body are the same thing anyway (unless I'm mistaken about something?), so I don't think I'd've made the decision that the square chaps have made to enforce explicitly passing an empty body in the cases where a body is semantically required. (Shrugs.) |
This comment has been minimized.
This comment has been minimized.
robfletcher
commented
Jan 15, 2016
|
It's "trivially easy" to add a request body provided you're not using OkHttp under Retrofit, for example. I don't want to pollute my Retrofit API interface with a body parameter that's just going to confuse people using it. I tried to use an |
This comment has been minimized.
This comment has been minimized.
dagronnell
commented
Feb 10, 2016
|
What about |
This comment has been minimized.
This comment has been minimized.
|
You can add an empty body. |
pepyakin commentedApr 22, 2014
Hi, i'm encountering same problem as with #745, but at this time with POST method.
I don't really care what specs saying about whether POST must have a body or not, but I definitely know, that some server APIs don't expect any body at all with POST method.
Let's not blame creators of such API's, but just admit it.
So, when dealing with such APIs I should use clumsy code like following one:
Maybe we should add "Content-Length: 0" header automatically if request's body is null?