when using androids URL and HttpUrlConnection to send a GET request to a backend point, it sometimes (1 out of 10) occurs, that the request fails due to: java.net.ProtocolException: Unexpected status line: 1.1 200 OK
As said this only happens somtimes, I tried 3 different backends (one of them self hosted) and it still occurs.
System.setProperty("http.keepAlive", "false");
URL url = new URL(callUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setUseCaches(false);
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
con.setConnectTimeout(5000);
con.setReadTimeout(4000);
con.setRequestMethod(requestMethod);
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
con.setRequestProperty("Accept-Charset", "UTF-8");
con.setRequestProperty("charset", "UTF-8");
con.setRequestProperty("Connection", "close");
Maybe someone has an idea how to fix it?