I am using HttpURLConnection
along the lines of the following:
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 just fine, with the url defined by strURL
returning a bmp image, and this being decoded ready for use by the above code.
But for one user in particular, although the code works fine to fetch the bmp image, at the server (a node.js server at heroku) it is apparent that a CONNECT
request is also being sent by their device. That request is rejected with a 503 response automatically, so it's not a problem as such, and the bmp is still sent to their device, but I'd like to know why those CONNECT
requests are being sent at all, and how to stop them. Surely there should be nothing but GET
requests?
I've tried this solution to what appears to be a similar problem, but it makes no difference for me.
Note that strURL
is to an https server, and I'm using HttpURLConnection
(not Https
) -- not sure if there is any significance in that.
I'm also not 100% sure the CONNECT
requests derive from the above calls, but they certainly happen around the same time as a GET
request that delivers the bmp. Maybe it could be generated by the OS somehow, outside of my code? Not sure.
In case it helps, an example log message from heroku, in response to one of the CONNECT
requests, 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 be of relevance that the device concerned actually makes two independent GET requests within a short time of each other (completely separate and legitimate requests), but there is only ever a single CONNECT request apparent (around the same time as the pair of GET requests). So it's not as if there is a CONNECT for each GET.