幾個月後,我的應用程序工作正常,但是在幾周內,我有時會遇到此錯誤,當我執行順序請求時。我沒有更新我的應用程序中的任何內容。 iOS版本的應用程序沒有問題,但我有時會特別在第一次請求時收到此錯誤。Retrofit + OkHttp意外的狀態行<!DOCType html>
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
這不是一個翻新問題,您的API正在返回一個HTML而不是JSON/XML,無論您希望如何。我建議如果你試圖在瀏覽器休息客戶端發出同樣的請求並查看響應。您應該調試並查找改進後傳遞的確切url和字段/查詢/頭。 – Milan