Results 1 to 4 of 4
  1. #1
    MrFish is offline Member
    Join Date
    Jan 2010
    Posts
    43
    Rep Power
    0

    Default Get url after redirect?

    I'm using URLConnection to connect to websites. I've got an issue where I follow a URL and get redirected to a new page. I can get the HTML of this page but I need to be able to get the URL of this new page. I tried-

    Java Code:
    			url = new URL(u);
    			connection = url.openConnection();
    			connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
    			url2 = connection.getURL();
    			returnURL = url2.getHost() + url2.getPath();
    returnURL comes back with the URL I opened. But I visit the url in my browser and get redirected to a new site. So the URL coming back is incorrect. How can I get the redirected URL?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default

    Did you try searching the net? I found a number of solutions in just the first page of search results.

    db

  3. #3
    MrFish is offline Member
    Join Date
    Jan 2010
    Posts
    43
    Rep Power
    0

    Default

    Yah I did and I didn't find anything. But I've got it figured out.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

Similar Threads

  1. help with redirect
    By BOJANM in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-04-2011, 06:51 PM
  2. How to redirect to a specified location from a jsp
    By sasi.tati in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 11-03-2010, 08:54 AM
  3. setRequestProperty() after redirect
    By mrs_sheep in forum Networking
    Replies: 0
    Last Post: 04-09-2010, 06:59 PM
  4. URL Redirect from one TLD to another
    By R@hul in forum Web Frameworks
    Replies: 0
    Last Post: 12-20-2009, 06:10 AM
  5. Redirect IP to 127.0.0.1?
    By Bill89 in forum Advanced Java
    Replies: 12
    Last Post: 12-13-2009, 11:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •