Java code shows request redirect but browser does not redirect.Why? -
this question has reply here:
java urlconnection final redirected url 7 answersthe follwing url gives response code 301 when run through java.the url is: http://www.amazon.com/kindle-wireless-reading-display-globally/dp/b003fsudm4/ref=amb_link_353259562_2?pf_rd_m=atvpdkikx0der&pf_rd_s=center-10&pf_rd_r=11eyktn682a79t370am3&pf_rd_t=201&pf_rd_p=1270985982&pf_rd_i=b002y27p3m , redirect url gives per java code is:
http://www.amazon.com/kindle-keyboard-free-wi-fi-display/dp/b004hzya6e
code :
public class newtesturlconnection { public static void main(string[] args) throws ioexception { string url="http://rads.stackoverflow.com/amzn/click/b003fsudm4"; httpurlconnection con =(httpurlconnection) new url( url ).openconnection(); con.setinstancefollowredirects(false); con.connect(); inputstream = con.getinputstream(); system.out.println(con.getheaderfield("location")); system.out.println( "response code: " + con.getresponsecode() ); } }
but when open url in browser not redirect to:http://www.amazon.com/kindle-keyboard-free-wi-fi-display/dp/b004hzya6e. suggest why difference?
instancefollowredirects protected boolean instancefollowredirects if true, protocol automatically follow redirects. if false, protocol not automatically follow redirects. field set setinstancefollowredirects method. value returned getinstancefollowredirects method. default value based on value of static followredirects @ httpurlconnection construction time.
this class httpurlconnection docs
java
No comments:
Post a Comment