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(
while ((inputLine = in.readLine()) != null)
Thanks in advance,
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 "http://yahoo.com", 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.
URL yahoo = new URL("http://yahoo.com");
HttpURLConnection yc = (HttpURLConnection) yahoo.openConnection();
// don't automatically redirect
int code = yc.getResponseCode();
// if redirected, outputs the redirect location
// (otherwise, null)
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..