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 -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -