Retrofit java.net.ProtocolException: Expected ':status' header not present
Asked Answered
U

2

2

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.

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));

And

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

  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.

Note 1: - This is working fine in Samsung S4 (Android verison 4.4.2) device. and in logs showing "OkHttp-Selected-Protocol: http/1.1" but it's not working in Android 5.1.1, 6.0.1, 7.1 & Android 8.1.0

Note 2: - It was working perfectly without setting any explicitly HTTP1.1 protocol but it suddenly stopped working (in device 5.1.1, 6.0.1, 7.1 & Android 8.1.0).

Here is the logs,

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)
Unexampled answered 28/3, 2018 at 9:50 Comment(0)
R
1

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.

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.

Rodriques answered 30/3, 2018 at 2:6 Comment(2)
Thanks @iagreen, for quick response, how can we make sure that it happened because of serve side changes, I talked to serve side people and they were saying... No change at all from side. So if they didn't change it then who changed it? Or there is anything automatic upgradation?Unexampled
I tested that our server does not support for SPDY protocol, i checked by this spdycheck.orgUnexampled
S
-1

Note : If you are using both apache httpmime and retrofit simultaneously Use apache httpmime older version.

(eg : in my case i used this to upload a image on server and also to get the content lenghth/image size)

This his an older version (not so old) or prev version, You should implement same old version for both.

implementation 'com.squareup.retrofit2:retrofit:2.0.2' implementation 'org.apache.httpcomponents:httpmime:4.3.6'

This his an new version of retrofit, You should use old version apache httpmime.

implementation 'com.squareup.retrofit2:retrofit:2.3.0' implementation 'org.apache.httpcomponents:httpmime:4.3.6'

Thank You so much, If u loved my solution plz voteup for me.

Subbasement answered 11/9, 2019 at 10:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.