OKHTTP 3G上的意外状态线

时间:2014-12-29 09:08:29

标签: android retrofit okhttp

我正在开发一个应用程序,我在使用okhttp发出POST请求时遇到问题。

堆栈跟踪(okhttp):

12-29 09:29:55.829: W/System.err(1797): java.net.ProtocolException: Unexpected status line: HTTP/1.1 
12-29 09:29:55.829: W/System.err(1797):     at com.squareup.okhttp.internal.http.StatusLine.parse(StatusLine.java:58)
12-29 09:29:55.837: W/System.err(1797):     at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:189)
12-29 09:29:55.837: W/System.err(1797):     at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:101)
12-29 09:29:55.845: W/System.err(1797):     at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:676)
12-29 09:29:55.845: W/System.err(1797):     at com.squareup.okhttp.Call.getResponse(Call.java:205)
12-29 09:29:55.845: W/System.err(1797):     at com.squareup.okhttp.Call.execute(Call.java:80)
12-29 09:29:55.852: W/System.err(1797):     at net.claxi.driver.misc.TaskFragment$LoginTask.doInBackground(TaskFragment.java:156)
12-29 09:29:55.852: W/System.err(1797):     at net.claxi.driver.misc.TaskFragment$LoginTask.doInBackground(TaskFragment.java:1)
12-29 09:29:55.852: W/System.err(1797):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-29 09:29:55.852: W/System.err(1797):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-29 09:29:55.852: W/System.err(1797):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-29 09:29:55.860: W/System.err(1797):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-29 09:29:55.860: W/System.err(1797):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-29 09:29:55.860: W/System.err(1797):     at java.lang.Thread.run(Thread.java:856)

这只发生在特定平板电脑上的3G上,在Wi-Fi上它可以在同一台设备上正常工作。在其他设备上,它可以在3G和Wi-Fi上正常工作。

对于登录请求,我使用okhttp发出请求。对于我正在使用Retrofit的其他请求。当我切换到使用Rertofit登录请求时,会发生奇怪的事情。有时它会起作用,有时它会崩溃。

使用Retrofit时的堆栈跟踪:

12-29 09:42:51.337: D/Retrofit(2766): ---- ERROR http://MYSERVER.com:2258/api/loginTaxi
12-29 09:42:51.352: D/Retrofit(2766): java.net.ProtocolException: Unexpected status line: HTTP/1.1 
12-29 09:42:51.352: D/Retrofit(2766):   at com.squareup.okhttp.internal.http.StatusLine.parse(StatusLine.java:59)
12-29 09:42:51.352: D/Retrofit(2766):   at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:187)
12-29 09:42:51.352: D/Retrofit(2766):   at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:78)
12-29 09:42:51.352: D/Retrofit(2766):   at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:665)
12-29 09:42:51.352: D/Retrofit(2766):   at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:429)
12-29 09:42:51.352: D/Retrofit(2766):   at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:374)
12-29 09:42:51.352: D/Retrofit(2766):   at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:469)
12-29 09:42:51.352: D/Retrofit(2766):   at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:73)
12-29 09:42:51.352: D/Retrofit(2766):   at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38)
12-29 09:42:51.352: D/Retrofit(2766):   at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:321)
12-29 09:42:51.352: D/Retrofit(2766):   at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
12-29 09:42:51.352: D/Retrofit(2766):   at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
12-29 09:42:51.352: D/Retrofit(2766):   at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
12-29 09:42:51.352: D/Retrofit(2766):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-29 09:42:51.352: D/Retrofit(2766):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-29 09:42:51.352: D/Retrofit(2766):   at retrofit.Platform$Android$2$1.run(Platform.java:142)
12-29 09:42:51.352: D/Retrofit(2766):   at java.lang.Thread.run(Thread.java:856)
12-29 09:42:51.352: D/Retrofit(2766): ---- END ERROR

我正在使用okhttp-2.1.0,okhttp-urlconnection-2.1.0和okio-1.1.0。

删除okhttp(使用默认http客户端的Retrofit)

12-29 10:24:19.837: D/Retrofit(4727): java.lang.IllegalArgumentException: Invalid status code: -1
12-29 10:24:19.837: D/Retrofit(4727):   at retrofit.client.Response.<init>(Response.java:42)
12-29 10:24:19.837: D/Retrofit(4727):   at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:94)
12-29 10:24:19.837: D/Retrofit(4727):   at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38)
12-29 10:24:19.837: D/Retrofit(4727):   at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:321)
12-29 10:24:19.837: D/Retrofit(4727):   at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
12-29 10:24:19.837: D/Retrofit(4727):   at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
12-29 10:24:19.837: D/Retrofit(4727):   at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
12-29 10:24:19.837: D/Retrofit(4727):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-29 10:24:19.837: D/Retrofit(4727):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-29 10:24:19.837: D/Retrofit(4727):   at retrofit.Platform$Android$2$1.run(Platform.java:142)
12-29 10:24:19.837: D/Retrofit(4727):   at java.lang.Thread.run(Thread.java:856)
12-29 10:24:19.837: D/Retrofit(4727): ---- END ERROR

知道发生了什么事吗?

1 个答案:

答案 0 :(得分:0)

默认的APN包含一个混乱我们的请求/响应的代理。

从APN中删除代理可以解决问题。