ProtocolException: Expected ':status' header not present

后端 未结 4 1003
粉色の甜心
粉色の甜心 2020-12-05 19:06

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 f

相关标签:
4条回答
  • 2020-12-05 19:15

    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
    
    0 讨论(0)
  • 2020-12-05 19:21

    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

    0 讨论(0)
  • 2020-12-05 19:30

    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);
    
    0 讨论(0)
  • 2020-12-05 19:35

    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'
    
    0 讨论(0)
提交回复
热议问题