Results 1 to 3 of 3
Thread: HTTP URL 301 redirect.
- 12-09-2009, 11:28 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 2
- Rep Power
- 0
HTTP URL 301 redirect.
Hi,
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(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
System.out.println(inputLine);
out.write(inputLine);
}
Thanks in advance,
Rag.
- 12-10-2009, 01:05 AM #2
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.
Java Code:URL yahoo = new URL("http://yahoo.com"); HttpURLConnection yc = (HttpURLConnection) yahoo.openConnection(); // don't automatically redirect yc.setInstanceFollowRedirects(false); int code = yc.getResponseCode(); System.out.println(code); // if redirected, outputs the redirect location // (otherwise, null) System.out.println(yc.getHeaderField("Location"));Last edited by CodesAway; 12-10-2009 at 01:08 AM.
CodesAway - codesaway.info
writing tools that make writing code a little easier
- 12-10-2009, 02:36 AM #3
Member
- Join Date
- Dec 2009
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Redirect IP to 127.0.0.1?
By Bill89 in forum Advanced JavaReplies: 12Last Post: 12-13-2009, 11:40 AM -
HTTP Status 405 - HTTP method GET is not supported by this URL
By javanewbie in forum Java ServletReplies: 7Last Post: 11-11-2009, 08:29 PM -
Http change to HTTP\SSL
By ballyv24 in forum Advanced JavaReplies: 0Last Post: 05-14-2008, 11:32 AM -
How to redirect the output
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:36 PM -
how to redirect the browser
By simon in forum Java AppletsReplies: 1Last Post: 08-02-2007, 05:24 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks