ProtocolException: Expected ':status' header not present

孤者浪人 提交于 2019-11-27 21:16:18

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'

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

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

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!