I am using HttpURLConnection in the following lines:
String strURL = "https://example.herokuapp.com"; Bitmap bmImage = null; HttpURLConnection connection = null; InputStream in = null; showMessage(context.getString(R.string.message_preparing)); try { int timeoutMS = 15000; URL url = new URL(strURL); connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.setConnectTimeout(timeoutMS); connection.setReadTimeout(timeoutMS); connection.connect(); in = connection.getInputStream(); BitmapFactory.Options options = new BitmapFactory.Options(); bmImage = BitmapFactory.decodeStream(in, null, options); } catch (Exception e) { e.printStackTrace(); } finally { if (connection != null) connection.disconnect(); if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } return bmImage;
This works fine, with the url defined by strURL returning a bmp image and this will be decoded for use by the above code.
But for one user, in particular, although the code works fine to extract the bmp image, on the server (node.js server in heroku) it is obvious that the CONNECT request is also sent to their device. This request is automatically rejected with a 503 response, so it is not a problem as such, and bmp is still sent to their device, but I would like to know why these CONNECT requests are sent at all, and how to Stop them. Surely there should be nothing but GET requests?
I tried this solution for what seems like a similar problem, but for me it does not make any difference.
Note that strURL refers to the https server, and I am using HttpURLConnection (not Https ) - not sure if there is any value to this.
I'm also not 100% sure that CONNECT requests stem from the above calls, but they certainly occur at about the same time as the GET request that BMP provides. Maybe this can be generated by the OS somehow outside of my code? Not sure.
In case this helps, an example of a log message from heroku in response to one of the CONNECT queries is as follows:
Oct 27 14:14:25 example heroku/router: at=error code=H13 desc="Connection closed without response" method=CONNECT path="example.herokuapp.com:443" host=example.herokuapp.com request_id=353e623x-dec4-42x5-bcfb-452add02ecef fwd="111.22.333.4" dyno=web.1 connect=0ms service=1ms status=503 bytes=0
EDIT: it may also matter that the corresponding device actually makes two independent GET requests within a short time from each other (completely separate and legitimate requests), but there is only one single CONNECT request (about the same time as a pair of GET requests). So it's not like there is a CONNECT for every GET.