commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adrian Sutton <>
Subject RE: [httpclient] Parse response for NameValuePairs?
Date Fri, 04 Apr 2003 03:48:01 GMT
Hi John,
I take it you wanted to get the name and value of all the headers returned
in the response.  You can use the getResponseHeaders() method in any
HttpMethod which will return an array of Headers.

Each header though can contain multiple values so you'd have to iterate over
the headers and the over the values for each header.  Something like:

Header[] headers = method.getResponseHeaders();
for (int i = 0; i < headers.length; i++) {
	String headerName = headers[i].getName();
	HeaderElement[] elements = headers[i].getValues();
	for (int j = 0; j < elements.length; j++) {
		HeaderElement el = elements[j];
		// At this stage you have the header and it's value.
		// See below for information on some "funky" headers

Some headers can contain multiple values within the header value, in
particular cookie headers do this.  You can repeat the pattern above to
iterate over the parameters of the HeaderElement to get a name value pair of
each element if that's what you want.  It really depends what level of
detail you need to go to.

Why were you wanting to do this?

Adrian Sutton, Software Engineer
Ephox Corporation

-----Original Message-----
From: John Burke []
Sent: Friday, 4 April 2003 1:17 PM
Subject: [httpclient] Parse response for NameValuePairs?

Hi, I've looked through the API docs but didn't find what I wanted.
I'm wondering if there is a method that will find and return all 
from a given response?  If not can anyone please suggest a few lines
of code?  Thanks.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message