java - URLConnection opening weirdness -


having tough time understanding urlconnection , connect() possibly being called implicitly.

this code doesn't work:

url url = new url(firsturl); httpurlconnection connection = (httpurlconnection) obj.openconnection(); conn.getheaderfield("location"); //returns null connection.setinstancefollowredirects(false); 

this code works:

url url = new url(firsturl); httpurlconnection connection = (httpurlconnection) obj.openconnection(); connection.setinstancefollowredirects(false); conn.getheaderfield("location"); //returns redirect url 

i'm having tough time understanding this. "getheaderfield" implicitly calling connect? don't see noted in documentation anywhere.

it connect, see http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/sun/net/www/protocol/http/httpurlconnection.java#httpurlconnection.getheaderfield%28java.lang.string%29 should mentioned in docs, agree...


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -