Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request add body throws EOFException #803

Closed
Zhouxuefei opened this issue May 5, 2014 · 16 comments
Closed

Request add body throws EOFException #803

Zhouxuefei opened this issue May 5, 2014 · 16 comments
Labels
bug Bug in existing code

Comments

@Zhouxuefei
Copy link

When the class com.squareup.okhttp.Call has been added.
when I called method call.execute();

the example throws a java.io.EOFException

at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:154)

String json = bowlingJson();
Request.Body body = Request.Body.create(MediaType.parse("application/json"), json);
Request request = new Request.Builder()
.url("https://xxxxxxxxx/api/1/user/phone_test")
.method("POST",body)
.build();

Call call = client.newCall(request);
Response response = call.execute();

But the earlier version of the example, Response response = client.execute(request);
It works.

In the latest version, the method " execute(Request request)" have goon.

@Zhouxuefei Zhouxuefei changed the title Request can not add parameters Request add body throws EOFException May 5, 2014
@swankjesse
Copy link
Collaborator

Can you give me a real URL to test against? If you'd like to share privately I'm [email protected]. I don't think the EOFException is at all related to the change in the way calls are executed.

@swankjesse swankjesse added the bug label May 5, 2014
@swankjesse swankjesse added this to the Icebox milestone May 5, 2014
@Zhouxuefei
Copy link
Author

I think it is a https problem . When I use the commit 'f4c83e8'. It works. But it does not have the class 'Call'

I have send you the sample class.

@swankjesse
Copy link
Collaborator

Works for me.

    String json = "{}";
    Request.Body body = Request.Body.create(MediaType.parse("application/json"), json);
    Request request = new Request.Builder()
        .url("https://xxxxx/api/1/user/phone_test")
        .method("POST",body)
        .build();

    OkHttpClient client = new OkHttpClient();
    Call call = client.newCall(request);
    Response response = call.execute();
    System.out.println(response.code());

@swankjesse
Copy link
Collaborator

@Zhouxuefei does the above code work for you on-device?

@Zhouxuefei
Copy link
Author

@swankjesse No. I have debug it. It will take so many time when ' call.execute(); ' run. And then throws a EOFException which is hardcode at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:154)

@Zhouxuefei
Copy link
Author

@swankjesse I have send you my sample code such as a Activity in Android. If I check out the commit 'f4c83e8' that using okio 0.7 ,it works .
And if I use the version above it. It will show a EOFException.

I'm sorry, I don't have enough time to fork it.
If I have time, I'll look at it.

and can you use JDK 6 to test it, if it does not take you a lot of time.
Because of the Android is build in JDK6. thanks a lot.

@swankjesse
Copy link
Collaborator

I'll take a look!

@Zhouxuefei
Copy link
Author

@swankjesse I have test it, twitter throws EOFException, and facebook can return response.

Request request = new Request.Builder()
    .url("https://api.twitter.com")
    .build();

OkHttpClient client = new OkHttpClient();
Response response = client.newCall(request).execute();

@Zhouxuefei
Copy link
Author

@swankjesse the version 2.0.0-RC1 can work

@simtse
Copy link

simtse commented Oct 23, 2014

I am using
Retrofit 1.6.1
okhttp 2.0.0
okhttp-urlconnection 2.0.0
okio 1.0.0

and when I try to make a call to one of my servers on HTTPs that looks something like this

HTTP https://..com/service/mobile/1.0/141022

I get

Caused by: java.io.EOFException: null
    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:154) ~[na:0.0]
    at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:189) ~[na:0.0]
    at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:101) ~[na:0.0]
    at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:676) ~[na:0.0]
    at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:426) ~[na:0.0]
    at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:371) ~[na:0.0]
    at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:466) ~[na:0.0]
    at com.squareup.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105) ~[na:0.0]
    at com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25) ~[na:0.0]
    at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:73) ~[na:0.0]
    at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38) ~[na:0.0]
    at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:321) ~[na:0.0]

it does happen once in a while. But normally, the same calls I make to that URL work fine. Any thoughts?

@swankjesse
Copy link
Collaborator

At first glance it looks like bad connection reuse, but that should be recovered from & retried automatically. Is this a POST request?

@simtse
Copy link

simtse commented Oct 23, 2014

Oh yes I noticed people had retry code square/retrofit#397 but not sure if that is the ideal way of handling it.

Oh yes, this is a POST request for an RPC call. Cheers!

@wizchentong
Copy link

I have the same problem. please fix it.
Device: Coolpad F1(8297W)with MIUI
Library: OkHttp2.0 Okio1.0
Log:

10-29 17:18:30.036: W/System.err(20871): java.io.EOFException
10-29 17:18:30.040: W/System.err(20871):    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:154)
10-29 17:18:30.041: W/System.err(20871):    at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:189)
10-29 17:18:30.044: W/System.err(20871):    at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:101)
10-29 17:18:30.045: W/System.err(20871):    at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:676)
10-29 17:18:30.046: W/System.err(20871):    at com.squareup.okhttp.Call.getResponse(Call.java:205)
10-29 17:18:30.047: W/System.err(20871):    at com.squareup.okhttp.Call.execute(Call.java:80)
10-29 17:18:30.048: W/System.err(20871):    at com.czt.okhttpdemo.MainActivity$1.run(MainActivity.java:34)

@eladgel
Copy link

eladgel commented Oct 29, 2014

Having the same issue when using POST

@swankjesse
Copy link
Collaborator

Tracking the EOFException here: #1114

@ZengCS
Copy link

ZengCS commented Apr 11, 2017

This issue occurred daily,kill it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in existing code
Projects
None yet
Development

No branches or pull requests

6 participants