commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Burke <>
Subject Re: [httpclient] Parse response for NameValuePairs?
Date Fri, 04 Apr 2003 23:44:16 GMT
Hello Adrian,
I'm using httpclient to automate the process of using an online
reservation system.  This is the first project I have used it for
so I'm am grasping at some new concepts.  At one point in the
script, I execute a get method and I get a few kilobytes from the
server.  Buried in there is a :  <INPUT TYPE="radio" NAME="xxx"
VALUE="yyy"> tag.  There may be more than one, but I have to respond
with my choice in the next POST method if I want to continue the
reservation process.  I thought the getmethod class might have a
method that culls the server response for these gems and returns
a set of NameValuePair class instances.  It would make building
the post method a little easier for the newbies, but I may just be lazy.
How would you handle this?
Thanks for your response.

On Thursday, Apr 3, 2003, at 22:48 America/New_York, Adrian Sutton 

> 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
> To:
> 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
> NameValuePairs
> from a given response?  If not can anyone please suggest a few lines
> of code?  Thanks.
> John
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:
John Burke
Booz | Allen | Hamilton Inc.
(732) 935-5120

View raw message