googolmo / OkVolley

A volley library used okhttp
Apache License 2.0
71 stars 27 forks source link

Empty post request fails #7

Closed baneizalfe closed 8 years ago

baneizalfe commented 8 years ago

When trying to send post request without any fields i get error

Caused by: java.lang.IllegalArgumentException: method POST must have a request body.
            at com.squareup.okhttp.Request$Builder.method(Request.java:236)
            at retrofit.client.OkClient.createRequest(OkClient.java:59)
            at retrofit.client.OkClient.execute(OkClient.java:53)

Thisi s known issue since okhttp 2.4 and was supposed to bi fixed in 2.5 (but isn't)

My fast and nasy workaround in OkKttpStack.java was

if (postBody == null) {
    builder.post(RequestBody.create(MediaType.parse(request.getBodyContentType()), ""));
} else {
    builder.post(RequestBody.create(MediaType.parse(request.getBodyContentType()), postBody));
}
googolmo commented 8 years ago

Ok I will try to workaround it.

googolmo commented 8 years ago

8 fix it