Dan Bezdek wrote:
Hi Everyone,
Hi Dan,
I am new to HttpClient, and I am a little confused regarding a few
issues. Here are my issues:
1. What is the best way to take care of relative redirects. I am
basically adding a method that will check the redirect path and if
path is relative, then it would add the server's url, or the url of
the context to the beginning of the path. My question is what is
the best way to get my hand on the server's url and the context's
url. I could pass these values in, but I want to be able to retrieve
these values from one of the classes in the HttpClient rather than
pass them in. After all, they must be stored somewhere like in the
HttpMethod that is being executed. Also, please let me know if there
is better way of handling relative redirects.
The method's URI is modified when a redirect is being followed. So you
may call method.getURI() and use host and path from there to complete
the relative redirection URI.
Little note: Actually RFC 2616 mandates the use of absolute URIs in the
Location header. But you can safely regard that as a shortsighted flaw
in the spec. It assumes that redirecting application can produce a full
URL that the calling client can use to access the resource. Of course
that can be very hard with reverse proxies, firewalls, NAT, port
forwarding and virtual hosts or URL contexts within webapps and
scripting environments. Depending on where in the network a client is
the URL to the same resource may look completely different. Thus nearly
all real-world applications issue relative redirects and violate the
letters of the spec. Actually is anybody going to modify this part of
the spec in the next release?
2. HttpResponse class. This class seems to have a lot of interesting
such as . However, I can't find any way of obtaining the
HttpResponse instance associated with a method that I have just
executed. I execute my method in the following way:
HttpClient httpClient = new HttpClient();
> GetMethod getMethod = new GetMethod(url);
> getMethod.setFollowRedirects(true);
> int responseCode = httpClient.executeMethod(getMethod);
Now, how can I obtain a reference to the HttpResponse associated with
the method executed above?
There is no such class in HttpClient 3. Use the following methods of the
HttpMethod:
- getResponseHeaders
- getResponseBodyAsStream
- getResponseFooters
- getStatusLine
3. When I look at the latest API, there is no HttpResponse, but when
I search through mailing list or web, I get a lot of posting that
includes references to HttpResponse. Is HttpResponse somehow
deprecated or something?
HttpResponse is an interface of Http Core of HttpComponents. It will be
used in version 4 of the HttpClient. The concept of HttpClient 3 is
flawed in that respect as it assumes a 1:1 relationship between request
and responses.
Thanks for taking time time to respond to my post. Dan
YAW
Ortwin
--
[web] http://www.odi.ch/
[blog] http://www.odi.ch/weblog/
[pgp] key 0x81CF3416
finger print F2B1 B21F F056 D53E 5D79 A5AF 02BE 70F5 81CF 3416
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]