改造+ OkHttp意外状态行

时间:2015-10-14 03:14:41

标签: android retrofit okhttp

几个月来我的应用程序运行正常,但在几周内,当我执行顺序请求时,我会收到此错误。我没有在我的应用程序中更新任何内容。关闭应用程序的iOS版本没有问题,但我有时会收到此错误,尤其是在我第一次请求时。

02-05 04:45:14.017  15972-16249/com.myapp.android D/Retrofit﹕ java.net.ProtocolException: Unexpected status line: <!DOCType html>
            at com.squareup.okhttp.internal.http.StatusLine.parse(StatusLine.java:73)
            at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:187)
            at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80)
            at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:791)
            at com.squareup.okhttp.internal.http.HttpEngine.access$200(HttpEngine.java:90)
            at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:784)
            at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:645)
            at com.squareup.okhttp.Call.getResponse(Call.java:263)
            at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:219)
            at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:192)
            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)
02-05 04:45:14.017  15972-16249/com.myapp.android D/Retrofit﹕ ---- END ERROR

2 个答案:

答案 0 :(得分:1)

此错误是由连接重用问题引起的。您知道上一个响应的响应代码和标题吗? OkHttp将其解释为没有正文,服务器不同意。

答案 1 :(得分:0)

将标题值设置为,

@Headers("Connection:close")

为我工作。