我正在使用retrofit和okhttp进行服务器调用。但有时我得到一个错误,它会跟随以下日志崩溃。(我正在使用GET调用):
日志:
: java.net.ProtocolException: unexpected end of stream
at com.squareup.okhttp.internal.http.Http1xStream$ChunkedSource.read(Http1xStream.java:442)
at okio.RealBufferedSource$1.read(RealBufferedSource.java:371)
at java.io.InputStream.read(InputStream.java:162)
at retrofit.Utils.streamToBytes(Utils.java:43)
at retrofit.Utils.readBodyToBytesIfNecessary(Utils.java:81)
at retrofit.RestAdapter.logAndReplaceResponse(RestAdapter.java:483)
at retrofit.RestAdapter.access$500(RestAdapter.java:107)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:338)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:818)
代码:
final OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setReadTimeout(60, TimeUnit.SECONDS);
okHttpClient.setConnectTimeout(60, TimeUnit.SECONDS);
RestAdapter restAdapter = new RestAdapter.Builder()
.setClient(new OkClient(okHttpClient))
.setEndpoint(URL).build();
myapi myapi_rest = restAdapter.create(myapi.class);
myapi_rest.my_call(
sno,
new Callback<Response>() {
@Override
public void success(Response result, Response response) {
}
@Override
public void failure(RetrofitError error) {
// Log.i("Failure", "Error"+error.getMessage());
}
});