ProtocolException: Expected ':status' header not present
Asked Answered
G

4

19

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 but fails with HTTPS.

Here is the logs,

java.net.ProtocolException: Expected ':status' header not present
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.Http2xStream.readHttp2HeadersList(Http2xStream.java:262)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.Http2xStream.readResponseHeaders(Http2xStream.java:145)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:53)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-18 14:59:01.103 30746-30746/? W/System.err:     at codmob.com.campuswallet.app.ApiClient$1.intercept(ApiClient.java:66)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-18 14:59:01.104 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-18 14:59:01.104 30746-30746/? W/System.err:     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
10-18 14:59:01.104 30746-30746/? W/System.err:     at okhttp3.RealCall.access$100(RealCall.java:33)
10-18 14:59:01.104 30746-30746/? W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:120)
10-18 14:59:01.104 30746-30746/? W/System.err:     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
10-18 14:59:01.104 30746-30746/? W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
10-18 14:59:01.104 30746-30746/? W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
10-18 14:59:01.104 30746-30746/? W/System.err:     at java.lang.Thread.run(Thread.java:761)
Genethlialogy answered 18/10, 2017 at 9:45 Comment(2)
Have you resolved this already?Preussen
Try this link https://mcmap.net/q/485859/-http-2-protocol-not-working-with-okhttp/3448003Preussen
G
24

After hours of mess, finally got a solution. Updating Retrofit and Okhttp3 libraries to the latest version did the trick for me.

compile 'com.squareup.okhttp3:okhttp:3.9.0'

compile 'com.squareup.retrofit2:retrofit:2.3.0'
Genethlialogy answered 19/10, 2017 at 4:59 Comment(2)
By using this fix my problem still exist.Onaonager
This is not fix if your app is in production - users continue to experience issue until they update. @aradon answer explains reason and more appropriate will be both downgrade nginx and update oktthp.Frontogenesis
D
10

I am using OkHttp2 (2.7.5) and I solved this issue by forcing the client to use HTTP 1.1 protocol

OkHttpClient client = new OkHttpClient();
client.setProtocols(Arrays.asList(Protocol.HTTP_1_1)); // <- add this line
Duester answered 13/3, 2018 at 12:53 Comment(7)
What does it mean?Preussen
@BajrangHudda this line means that your OkHttp client will not try to use http2 protocol when is available. You just have to put this line into your client app source code and release a new version to production. That's it.Duester
ok, I got your point. But why app suddenly stop working? Yesterday it was working on same device but today it can work only by setting Protocol.Http.1.1. Why so?Preussen
@BajrangHudda maybe you or someone updated server engine to version, which supports http2 protocol. This was my reason.Duester
if it was the reason then, how problem solved by setting protocol http1.1? I am a bit confused, can you explain in detail?Preussen
And app with android device 4.4.2 still running fine without setting protocol http1.1.Preussen
@BajrangHudda This is my idea: http2 is new protocol and it seems older Android does not support it - so OkHttp2 uses only http1.1 which is working well. Newer Android versions support http2 and OkHttp2 (which does not handle http2 well) makes a decision "let's use this new http2 protocol because is available on a server" - and that's why it is not working.Duester
T
8

Today faced the same problem. The reason was in updating nginx on the server to the latest version (1.13.6). Ask your backend team if they did not update nginx on the server.

nginx changelog - http://nginx.org/en/CHANGES

Theft answered 18/10, 2017 at 11:13 Comment(3)
Post relevant parts of the linked page in the answer so that even if the page changes, the answer is still useful. stackoverflow.com/help/how-to-answerCordilleras
Updating to the latest version of okhttp3 (3.9.0) and retrofit2 (2.3,0) did the trick for me.Genethlialogy
But I am using sucuri, What can be the possible reason?Preussen
I
1

I am using okhttp3 (okhttp-3.4.1), okhttp3 is not very compatible with the HTTP_1.1 protocol and needs to be manually added. you can see Official link

OkHttpClient.Builder builder = new OkHttpClient.Builder();
//protocols
List<Protocol> protocols = new ArrayList<Protocol>();
protocols.add(Protocol.HTTP_1_1);
protocols.add(Protocol.HTTP_2);
builder.protocols(protocols);
Incompetence answered 16/4, 2018 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.