W3C home > Mailing lists > Public > www-jigsaw@w3.org > May to June 1997

Re: Handling of redirections (fwd)

From: Joseph M. Futrelle <futrelle@ncsa.uiuc.edu>
Date: Tue, 27 May 1997 11:23:28 -0500 (CDT)
Message-Id: <199705271623.LAA25298@pecos.ncsa.uiuc.edu>
To: www-jigsaw@w3.org

Use java.net.URL::openConnection().

See
 http://java.sun.com:80/products/jdk/1.1/docs/api/java.net.URLConnection.html
for a more detailed answer.

This example code hits altavista's "random" script, follows the redirect
that the script sends back, and prints some information about the target
object.

 URL redirector = new URL
  ("http://www.altavista.digital.com/cgi-bin/query?pg=s&target=0");
 HttpURLConnection c = (HttpURLConnection) redirector.openConnection();
 c.connect ();
 System.out.println (c.getResponseMessage() + " " + c.getContentLength());

You can disable redirect-following by inserting
 c.setFollowRedirects (false);
before connect().

Forwarded message:
> From www-jigsaw-request@w3.org Sat May 24 12:10 CDT 1997
> Date: Sat, 24 May 1997 10:03:01 -0700
> From: Mark Friedman <mark@intraspect.com>
> To: Anselm Baird-Smith <abaird@w3.org>
> CC: www-jigsaw@w3.org
> Subject: Re: Handling of redirections
> 
> I see. I guess I was just using the wrong API (I was using HTTPManager).
> So if I had a URL hanging around what would be the best/easiest way to
> get that URL and have redirection done automatically? Perhaps, another
> way of phrasing the question is: how can I get access to the
> HttpURLConnection API? Its constructor isn't public, so I assume that
> there is some other, public, way to make use of it.
> 
> -Mark
> 
> Anselm Baird_Smith wrote:
> 
> > Mark Friedman writes:
> >  > Looking at the HttpManager and HttpURLConnection, it seems that
> >  > redirection is not automatically handled by the HTTP client code
> > (except
> >  > to reset the request's URL). Is that true? If so, it would be nice
> > if
> >  > there could be an option to runRequest() to have it follow the
> >  > redirections.
> >
> > runRequest is meant to be "as stupi as possible" leaving any
> > cleverness to uppper layers (ie HttpURLConnection does the redirection
> >
> > - when you use it through the URLConnection API)
> >
> > Note that this is not entirely true when filters are used (ie the
> > AUthFilter will retry the request behind the runRequest'caller back)
> >
> > Anselm
> 
> 
> 
> 


-- 
Joe Futrelle
Developer, Joule/Jigsaw Java/HTTP
National Center for Supercomputing Applications
futrelle@ncsa.uiuc.edu
(217) 265-0296
Received on Tuesday, 27 May 1997 12:23:36 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 9 April 2012 12:13:26 GMT