1

I'm trying to do a POST request to my server with a json body. If my POST request does not have body, it works. If I have any body content, I get this EOFException. Please let me know if I missed any detail.

retrofit version 1.5.0
okhttp version 1.5.2

Message model:

public static class MyMessage{
    String local;
}

retrofit post:

@POST("/user/{user_id}/message")
void createMessage(
        @Path("user_id") long user_id,
        @Body MyMessage json,
        MyCallback cb);

Log error:

06-10 18:25:18.575: D/Retrofit(28598): ---> HTTP POST XXX/user/1111158/message
06-10 18:25:18.575: D/Retrofit(28598): Content-Type: application/json; charset=UTF-8
06-10 18:25:18.575: D/Retrofit(28598): Content-Length: 16
06-10 18:25:18.576: D/Retrofit(28598): {"local":"xyzw"}
06-10 18:25:18.576: D/Retrofit(28598): ---> END HTTP (16-byte body)
06-10 18:25:18.579: D/Retrofit(28598): ---- ERROR XXX/user/1111158/message
06-10 18:25:18.581: D/Retrofit(28598): java.io.EOFException
06-10 18:25:18.581: D/Retrofit(28598):  at com.squareup.okhttp.internal.okio.RealBufferedSource.readUtf8Line(RealBufferedSource.java:90)
06-10 18:25:18.581: D/Retrofit(28598):  at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:145)
06-10 18:25:18.581: D/Retrofit(28598):  at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:99)
06-10 18:25:18.581: D/Retrofit(28598):  at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:568)
06-10 18:25:18.581: D/Retrofit(28598):  at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:372)
06-10 18:25:18.581: D/Retrofit(28598):  at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:319)
06-10 18:25:18.581: D/Retrofit(28598):  at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:484)
06-10 18:25:18.581: D/Retrofit(28598):  at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:71)
06-10 18:25:18.581: D/Retrofit(28598):  at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38)
06-10 18:25:18.581: D/Retrofit(28598):  at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:358)
06-10 18:25:18.581: D/Retrofit(28598):  at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:264)
06-10 18:25:18.581: D/Retrofit(28598):  at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:315)
06-10 18:25:18.581: D/Retrofit(28598):  at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
06-10 18:25:18.581: D/Retrofit(28598):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
06-10 18:25:18.581: D/Retrofit(28598):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
06-10 18:25:18.581: D/Retrofit(28598):  at java.lang.Thread.run(Thread.java:841)
06-10 18:25:18.581: D/Retrofit(28598): ---- END ERROR
heloisasim
  • 4,956
  • 2
  • 27
  • 36
  • The server has closed the connection prematurely. Of course it's a server error, or at least it didn't like what you sent it. – user207421 Jun 11 '15 at 00:04
  • 1
    try with curl, postman, or whatever standalone http client, see what your server says. – njzk2 Jun 22 '15 at 18:35
  • I have the same problem, I know its no my server, because i copy the content of my request and use the Advance Rest Client on Chrome Browser and wokrs fine. The problem only happens with android. I'm running API 16 – Gatunox Jan 04 '16 at 03:39

0 Answers0