改造java.net.ProtocolException:预期的':status'标头不存在 [英] Retrofit java.net.ProtocolException: Expected ':status' header not present

查看:264
本文介绍了改造java.net.ProtocolException:预期的':status'标头不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行中的应用程序中,改造网络调用失败,并突然出现协议异常.该应用程序一直运行到昨天,今天所有网络调用均失败.这些调用可以在HTTP和某些HTTPS上正常工作,除了我的产品端点.

Retrofit network calls fails with a Protocol Exception suddenly in a working app. The app was working till yesterday and today all the network calls fails. The calls works fine with HTTP and with some HTTPS except my production endpoint.

看来,该应用程序不仅只能在我使用过的 https端点上运行,而且还可以与其他https端点一起运行.

It seems that app is not working only on my used https endpoint but working with other https endpoint, I tried.

我以这种方式解决了这个问题-

I fixed the problem this way -

OkHttpClient client = new OkHttpClient();
client.setProtocols(Arrays.asList(Protocol.HTTP_1_1));

还有

我的问题得到了解决,除此以外,将使用过的库okhttp2升级到okhttp3之后,在相同的 https端点下也可以正常工作.

And my problem solved and except this after upgrading my used library okhttp2 to okhttp3 also working fine with same https endpoint.

  1. 我不明白什么是真正的原因?
  2. 如果okhttp2出现问题,那么为什么最近可以正常使用?
  3. 为什么在特定的端点上有问题,并且对某些端点正常工作?
  1. I don't understand what can be the real cause?
  2. And if it's problem with okhttp2 then why it was working recently?
  3. And why it's problem on a specific endpoint and working fine for some endponits?

我遵循了

I followed this and this link but still I don't understand whats the real problem.

注意1:-在Samsung S4(Android版本4.4.2)设备中,此功能正常工作.并在显示"OkHttp-Selected-Protocol:http/1.1"的日志中显示,但在Android 5.1.1、6.0.1、7.1及更高版本中不起作用Android 8.1.0

注意2:-无需设置任何明确的HTTP1.1协议即可正常运行,但突然停止工作(在设备5.1.1、6.0.1、7.1和Android 8.1.0中).

这是日志,

java.net.ProtocolException: Expected ':status' header not present at
com.squareup.okhttp.internal.http.SpdyTransport.readNameValueBlock(SpdyTransport.java:197)at com.squareup.okhttp.internal.http.SpdyTransport.readResponseHeaders(SpdyTransport.java:104)
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:917)
at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:95)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:902)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:760)
at com.squareup.okhttp.Call.getResponse(Call.java:274)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:230)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:201)                                                                                         
at com.squareup.okhttp.Call.execute(Call.java:81)
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$2.obtainResponse(RestAdapter.java:278)                                                                                            
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)                                                                                       
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)                                                                                     
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)                                                                                      
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:818)

推荐答案

您的崩溃来自SpdyTransport.java,这是正在发生的事情的线索. SPDY 已被弃用并正在逐步淘汰.服务器配置的更改最类似于您所看到的说明.可能是删除或修改了对SPDY的支持的更新.升级到okhttp3是适用于您的应用程序的正确修复程序. Okhttp3不支持SPDY,因此不会尝试建立SPDY连接.服务器运行不同的软件并具有不同的配置,从而解释了旧版本只能用于某些端点而不能用于其他端点的原因.

Your crash is coming from SpdyTransport.java which is the clue to what is happening. SPDY has been deprecated and is being phased out. A change in server configuration is the most like explanation for what you are seeing. Probably an update that drops or modifies support for SPDY. Upgrading to okhttp3 is the correct fix for your app. Okhttp3 does not support SPDY, so will not try to make a SPDY connection. The reason the old works with some endpoints and not others is explained by the servers running different software and having different configurations.

它可以在您的4.4.2设备上正常工作的原因是,Android直到5.0才支持SPDY,因此该设备从未尝试使用SPDY连接.

The reason it worked and continued to work on your 4.4.2 device is that android did not support SPDY until 5.0, so that device never attempted to use a SPDY connection.

这篇关于改造java.net.ProtocolException:预期的':status'标头不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆