java - How it comes that URL.openConnection() allows me to read header? -
i experimenting java networking , found bit odd thing, suppose have
url url = new url("http://www.google.com"); urlconnection con = url.openconnection();
then can call methods, con.getcontentlength()
, on , give me correct values, despite didn't envoke con.connect()
. how can be? mean, from/how urlconnection gets headers, didn't invoke con.connect()
yet, no requests sent , no headers should available @ moment.
the actual tcp connect happens implicitly when call method requires response, such getcontentlength(), getinputstream(), getresponsecode(). doesn't happen @ openconnection(). request sent @ point.
unless using 1 of streaming modes , you're doing put or post request content, in case connection opened when start writing request.
Comments
Post a Comment