android用okhttp和retrofit访问网络的时候有时候出现EOFException异常
来源:互联网 发布:java读取csv文件内容 编辑:程序博客网 时间:2024/06/03 01:21
android用okhttp和retrofit访问网络的时候有时候出现EOFException异常
at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:211)
at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80)
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:906)
at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:92)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:891)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:749)
at com.squareup.okhttp.Call.getResponse(Call.java:268)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)
at com.sogou.bizdev.mobileyunguan.api.ReceivedCookiesInterceptor.intercept(ReceivedCookiesInterceptor.java:19)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:221)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
at com.squareup.okhttp.Call.execute(Call.java:79)
at retrofit.client.OkClient.execute(OkClient.java:53)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$1.invoke(RestAdapter.java:265)
at retrofit.RxSupport$2.run(RxSupport.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.io.EOFException: \n not found: size=0 content=...
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:201)
at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:191)
at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80)?
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:906)?
at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:92)?
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:891)?
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:749)?
at com.squareup.okhttp.Call.getResponse(Call.java:268)?
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)?
at com.sogou.bizdev.mobileyunguan.api.ReceivedCookiesInterceptor.intercept(ReceivedCookiesInterceptor.java:19)?
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:221)?
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)?
at com.squareup.okhttp.Call.execute(Call.java:79)?
at retrofit.client.OkClient.execute(OkClient.java:53)?
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)?
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)?
at retrofit.RestAdapter$RestHandler$1.invoke(RestAdapter.java:265)?
at retrofit.RxSupport$2.run(RxSupport.java:55)?
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)?
at java.util.concurrent.FutureTask.run(FutureTask.java:237)?
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)?
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)?
at retrofit.Platform$Android$2$1.run(Platform.java:142)?
at java.lang.Thread.run(Thread.java:841)?
---- END ERROR
unexpected end of stream on Connection{10.144.59.130:8291, proxy=DIRECT@ hostAddress=10.144.59.130 cipherSuite=none protocol=http/1.1} (recycle count=9)
retrofit.RetrofitError: unexpected end of stream on Connection{10.144.59.130:8291, proxy=DIRECT@ hostAddress=10.144.59.130 cipherSuite=none protocol=http/1.1} (recycle count=9)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:395)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$1.invoke(RestAdapter.java:265)
at retrofit.RxSupport$2.run(RxSupport.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.io.IOException: unexpected end of stream on Connection{10.144.59.130:8291, proxy=DIRECT@ hostAddress=10.144.59.130 cipherSuite=none protocol=http/1.1} (recycle count=9)
at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:211)
at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80)
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:906)
at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:92)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:891)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:749)
at com.squareup.okhttp.Call.getResponse(Call.java:268)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)
at com.sogou.bizdev.mobileyunguan.api.ReceivedCookiesInterceptor.intercept(ReceivedCookiesInterceptor.java:19)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:221)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
at com.squareup.okhttp.Call.execute(Call.java:79)
at retrofit.client.OkClient.execute(OkClient.java:53)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)?
at retrofit.RestAdapter$RestHandler$1.invoke(RestAdapter.java:265)?
at retrofit.RxSupport$2.run(RxSupport.java:55)?
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)?
at java.util.concurrent.FutureTask.run(FutureTask.java:237)?
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)?
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)?
at retrofit.Platform$Android$2$1.run(Platform.java:142)?
at java.lang.Thread.run(Thread.java:841)?
Caused by: java.io.EOFException: \n not found: size=0 content=...
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:201)
at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:191)
at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80)?
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:906)?
at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:92)?
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:891)?
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:749)?
at com.squareup.okhttp.Call.getResponse(Call.java:268)?
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)?
at com.sogou.bizdev.mobileyunguan.api.ReceivedCookiesInterceptor.intercept(ReceivedCookiesInterceptor.java:19)?
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:221)?
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)?
at com.squareup.okhttp.Call.execute(Call.java:79)?
at retrofit.client.OkClient.execute(OkClient.java:53)?
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)?
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)?
at retrofit.RestAdapter$RestHandler$1.invoke(RestAdapter.java:265)?
at retrofit.RxSupport$2.run(RxSupport.java:55)?
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)?
at java.util.concurrent.FutureTask.run(FutureTask.java:237)?
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)?
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)?
at retrofit.Platform$Android$2$1.run(Platform.java:142)?
at java.lang.Thread.run(Thread.java:841)?
找了半天在StackOverFlow上找到了答案,虽然答案不是太理想,但是确实解决了这个问题,在此记录一下
答案如下:
This was not a well documented answer. It appears in some of the newer versions of android, there is a bug with recycled url connections. To fix this (although there may be some performance issues), I needed to add:
if (Build.VERSION.SDK != null && Build.VERSION.SDK_INT > 13) { urlConnect.setRequestProperty("Connection", "close");}
或:
if (Build.VERSION.SDK != null && Build.VERSION.SDK_INT > 13) { request.addHeader("Connection", "close");}
主要就是在http header里面增加关闭连接,不让它保持连接。
主要是在回收url connection有可能有问题,后来我也增加了连接关闭,不保持url connection,这样就解决了,但是付出了性能的代价。
继续查找看有没有更好的办法。
0 0
- android用okhttp和retrofit访问网络的时候有时候出现EOFException异常
- 使用Okhttp访问网络可能出现的bug——EOFException异常
- Okhttp频繁访问网络时候的错误
- Android网络缓存,retrofit+okhttp
- okhttp+retrofit常见网络异常收集
- Android网络请求发展简史和RxJava+Retrofit+OkHttp实践
- Android网络请求发展简史和RxJava+Retrofit+OkHttp实践
- Android Retrofit+rxjava+okhttp请求网络的基本用法
- Android中Retrofit+OkHttp进行HTTP网络编程的使用指南
- Android网络请求XUtils、Volley、OkHttp、Retrofit
- android 网络框架学习(okhttp,retrofit,rxjava)
- Android使用Retrofit+OkHttp实现网络请求
- Android okHttp的配置使用和Retrofit简单的配置
- 基于Rxjava+Retrofit+Okhttp的webservices访问
- Okhttp+Retrofit下访问百度音乐api出现403 forbidden的解决方案
- Android okHttp网络请求之Retrofit+Okhttp组合(五)
- Android okHttp网络请求之Retrofit+Okhttp+RxJava组合
- Android okHttp网络请求之Retrofit+Okhttp+RxJava组合
- Delphi-JAVA互加解密AES算法
- 鲁棒的实时人脸检测:Robust Real-Time Face Detection
- IOS申请发布证书-图文详解
- 图解教程]Eclipse不可不知的用法之一:自动生成Getter、Setter和构造方法
- CocosCreator教程资料索引[2016.2.18已更新]
- android用okhttp和retrofit访问网络的时候有时候出现EOFException异常
- poj 2891 一般模线性方程
- poj 1149 PIGS 网络流建图
- IOS 发布应用程序到App Store
- dom4j-Quick Start Guide
- 码农小汪-剑指Offer之18-包含min函数的栈
- 第4周项目5-用递归方法求解4
- CF_5A_ChatServer'sOutgoingTraffic
- HDOJ 2049 不容易系列之(4)——考新郎