url redirection - How can I calculate the number of times a webpage redirects in java? -


i have tried using following code, it's not working. please help.

httpurlconnection con = (httpurlconnection)(new url(url).openconnection());      con.setinstancefollowredirects( false );       con.connect(); int responsecode = ((httpurlconnection) con).getresponsecode(); int numberhops =0;  while (responsecode!=200)            {     string newurl = con.getheaderfield("location");     httpurlconnection conn = (httpurlconnection) new      url(newurl).openconnection();     con.setinstancefollowredirects( false );     responsecode = conn.getresponsecode();               numberhops++; } system.out.println(numberhops); 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -