改造“java.net.ProtocolException:意外的状态行”,任何人?

前端之家收集整理的这篇文章主要介绍了改造“java.net.ProtocolException:意外的状态行”,任何人?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的 Android应用程序崩溃了以下堆栈跟踪,但是当我从桌面休息客户端尝试它时它运行良好.有谁知道问题可能是什么?
04-23 16:00:50.449  27917-27983/com.iproperty.android.apps.irealtor D/Ireal_IrealtorClient﹕ ---> HTTP GET http://beta2.irealtor.api.iproperty.com.my/Listing?pageSize=10000&orderby=1&order=-1
04-23 16:00:50.449  27917-27983/com.iproperty.android.apps.irealtor D/Ireal_IrealtorClient﹕ If-Modified-Since: 1398235278243
04-23 16:00:50.449  27917-27983/com.iproperty.android.apps.irealtor D/Ireal_IrealtorClient﹕ User-Agent: Android/0.0.20
04-23 16:00:50.449  27917-27983/com.iproperty.android.apps.irealtor D/Ireal_IrealtorClient﹕ Accept: application/json
04-23 16:00:50.449  27917-27983/com.iproperty.android.apps.irealtor D/Ireal_IrealtorClient﹕ Authorization: WFdSeW8vOTJ1Z3BoQlBJMk53VGpaekZRY2pCd1pYSlVXUT090
04-23 16:00:50.449  27917-27983/com.iproperty.android.apps.irealtor D/Ireal_IrealtorClient﹕ ---> END HTTP (0-byte body)
04-23 16:00:50.549  27917-27983/com.iproperty.android.apps.irealtor D/Ireal_IrealtorClient﹕ ---- ERROR http://beta2.irealtor.api.iproperty.com.my/Listing?pageSize=10000&orderby=1&order=-1
04-23 16:00:50.549  27917-27983/com.iproperty.android.apps.irealtor D/Ireal_IrealtorClient﹕ java.net.ProtocolException: Unexpected status line: {"Data":[],"CustomStatusCode":200,"Status":"success"}HTTP/1.1 200 OK
            at com.squareup.okhttp.internal.http.StatusLine.<init>(StatusLine.java:38)
            at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:150)
            at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:99)
            at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:595)
            at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:381)
            at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:328)
            at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:493)
            at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:71)
            at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38)
            at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:358)
            at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:284)
            at $Proxy0.syncProperties(Native Method)
            at com.iproperty.android.apps.irealtor.sync.SyncHelper.performSync(SyncHelper.java:210)
            at com.iproperty.android.apps.irealtor.sync.SyncAdapter.onPerformSync(SyncAdapter.java:82)
            at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:259)
04-23 16:00:50.549  27917-27983/com.iproperty.android.apps.irealtor D/Ireal_IrealtorClient﹕ ---- END ERROR


/**Sample code by using BasicHttpClient*/
BasicHttpClient httpClientTest = new BasicHttpClient();
httpClientTest.addHeader("If-Modified-Since","1398312582192");
httpClientTest.addHeader("Authorization","WFdSeW8vOTJ1Z3BoQlBJMk53VGpaekZRY2pCd1pYSlVXUT090");
httpClientTest.addHeader("User-Agent","Android/0.0.20");
httpClientTest.addHeader("Accept","application/json");

HttpResponse responseTest = httpClientTest.get("http://beta2.irealtor.api.iproperty.com.my/Listing?pageSize=100&orderby=1&order=-1",null);
final int statusTest = responseTest.getStatus(); // here i get 204,because i make server return 204 then there is nothing.
String body responseTest.getAsString() // here i get empty which is correct.

解决方法

某些事情导致前一个HTTP请求的响应主体长度出现问题,并导致池化连接损坏.

前面的请求被OkHttp解释为没有正文,但它有这个正文:

{"Data":[],"Status":"success"}

它可能是服务器中的错误,也可能是OkHttp中的错误,具体取决于前面的URL发送的标头和代码.如果您可以粘贴此失败之前的请求,我们可以找出它的错误

猜你在找的Java相关文章