Results 1 to 3 of 3
  1. #1
    ssraghavan is offline Member
    Join Date
    Dec 2009
    Rep Power

    Default HTTP URL 301 redirect.


    I am trying to fetch all kinds of URL response, but i face the issue when it url is having 301 redirected response i am unable to fetch the url response . Can someone kindly help me to solve this issue.

    Piece of very basic code to pull out http url response is as follows..

    HttpURLConnection yc =(HttpURLConnection) yahoo.openConnection();
    int code = yc.getResponseCode ( ) ;

    System.out.println("mesg is"+ yc.getResponseMessage( ));

    // System.out.println("ok value is "+yc.HTTP_OK);

    BufferedReader in = new BufferedReader(
    new InputStreamReader(
    String inputLine;

    while ((inputLine = in.readLine()) != null)



    Thanks in advance,

  2. #2
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Rep Power


    I'm not sure what your question is or what you are trying to do. Are you trying to get a 301 message?

    Also, can you post a compilable program so that we can test it. For example, I presume that "yahoo" is a URL object with the site "", but it would be more helpful if you told us what yahoo was.

    I'm not sure if this is related, but page redirects are done automatically, by default. If you want to disable this, you can use the following.

    Java Code:
    URL yahoo = new URL("");
    HttpURLConnection yc = (HttpURLConnection) yahoo.openConnection();
    // don't automatically redirect
    int code = yc.getResponseCode();
    // if redirected, outputs the redirect location
    // (otherwise, null)
    Last edited by CodesAway; 12-10-2009 at 01:08 AM.
    CodesAway -
    writing tools that make writing code a little easier

  3. #3
    ssraghavan is offline Member
    Join Date
    Dec 2009
    Rep Power

    Default Thanks I got it,

    I was trying fetch the page response for all kinds of URL's and i got stuckup when the URL is being redirected as 301. Thanks, I found the way to find using
    getHeaderField(5) where it gets redirected to, and i get that url, and finally i get the page response..


Similar Threads

  1. Redirect IP to
    By Bill89 in forum Advanced Java
    Replies: 12
    Last Post: 12-13-2009, 11:40 AM
  2. Replies: 7
    Last Post: 11-11-2009, 08:29 PM
  3. Http change to HTTP\SSL
    By ballyv24 in forum Advanced Java
    Replies: 0
    Last Post: 05-14-2008, 11:32 AM
  4. How to redirect the output
    By Java Tip in forum
    Replies: 0
    Last Post: 04-04-2008, 02:36 PM
  5. how to redirect the browser
    By simon in forum Java Applets
    Replies: 1
    Last Post: 08-02-2007, 05:24 PM

Tags for this Thread

Posting Permissions

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