Hi I've started using HttpUrlConnection and I have a question regarding on when the Http Request is actually sent.
I read somewhere that the actual request is sent when getInputStream() is called. However, I've written some test code to play around with this for a POST request:
In this version I'm calling on getResponseCode() before getInputStream()
URL obj = new URL(myUrl);
HttpURLConnection httpclient = (HttpURLConnection) obj.openConnection();
httpclient.setRequestMethod("POST");
**int responseCode = httpclient.getResponseCode();**
try {
inStream = httpclient.getInputStream();
}
catch (IOException ie) {
inStream = httpclient.getErrorStream();
}
System.out.println("response code = " + responseCode);
I receive a response code of 200. So this got me thinking that the request is not being sent at getInputStream(), but at an earlier method. Does anyone have any insight on this?
Thanks!