Okhttp fails when there is REFUSED_STREAM in HTTP/2. This happens with newer versions of nginx that use HTTP/2. GET requests get processed correctly, however, for POST, it fails with nginx complaining that the client prematurely closed the stream.
client sent stream with data before settings were acknowledged while processing HTTP/2 connection
More info here - square/okhttp#2543 and square/okhttp#2506
Because of this, okhttp does not work with some of the newer nginx servers.
The fix is to configure OkHttpClient with other protocols for it to use. Here's the fix -- wallabag/android-app#256.
As per OkHttp's javadocs,
The client will prefer the most efficient transport available, falling back to more ubiquitous protocols.
If multiple protocols are specified, ALPN will be used to negotiate a transport.
However, if you enable all possible protocols (like I tried in the PR here #7641), you will still get PROTOCOL_ERRORS maybe half the time. So instead of the change, the solution might be to add this to your MainActivity.
@Override
protected void onStart() {
super.onStart();
OkHttpClient client = OkHttpClientProvider.getOkHttpClient();
List<Protocol> protocolList = new ArrayList<>();
protocolList.add(Protocol.HTTP_1_1);
client.setProtocols(protocolList);
}
Okhttp fails when there is
REFUSED_STREAMin HTTP/2. This happens with newer versions of nginx that use HTTP/2. GET requests get processed correctly, however, for POST, it fails with nginx complaining that the client prematurely closed the stream.client sent stream with data before settings were acknowledged while processing HTTP/2 connectionMore info here - square/okhttp#2543 and square/okhttp#2506
Because of this, okhttp does not work with some of the newer nginx servers.
The fix is to configure
OkHttpClientwith other protocols for it to use. Here's the fix -- wallabag/android-app#256.As per OkHttp's javadocs,
However, if you enable all possible protocols (like I tried in the PR here #7641), you will still get
PROTOCOL_ERRORSmaybe half the time. So instead of the change, the solution might be to add this to yourMainActivity.