You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Chris Ashurst <CA...@thig.com> on 2006/05/31 17:30:01 UTC

NameValuePair Clarification

I've been looking over the API for NameValuePair, and I've noticed that it
doesn't seem possible to append new NameValuePairs to an already existing
set.

This normally isn't a problem, as I guess people know precisely what they're
going to be sending, but I'm having an issue where I know the majority of
the variables I'm using in the request, but I have a varying number of
"flags" that can be sent with a request.

The flags themselves will all have the value of True attached to them, but
as I say, I can't see a way to extract them from their current state in a
list and put them into a bunch of NameValuePairs that I can then put into my
big NameValuePair for the request.

Does the request (in this case, POST) *have* to be in NameValuePair format?
Can I append extra variables onto the end of the data? I know I must be
missing something...

// SNIP //
ListIterator li = cdsRmTestList.listIterator();
		NameValuePair[] flags = null;
		while (li.hasNext()) {
			flags = new NameValuePair(li.next().toString(),
"True");
		}
		NameValuePair[] data = {
				new NameValuePair("txtName",
cdsName.toString()),
				new NameValuePair("txtStreet",
cdsStreet.toString()),
				new NameValuePair("txtCity",
cdsCity.toString()),
				new NameValuePair("txtState",
cdsState.toString()),
				new NameValuePair("txtZip",
cdsZip.toString()),
				new NameValuePair("txtPlus4",
cdsZipPlusFour.toString()),
				new NameValuePair("txtFirm",
cdsFirm.toString()),
				new NameValuePair("txtUserName",
"towerhilltest"),
				new NameValuePair("txtPassword",
"towerhilltest"),
				new NameValuePair("txtLat",
cdsLat.toString()),
				new NameValuePair("txtLon",
cdsLon.toString()),
				new NameValuePair("txtGeoResult",
cdsGeoResult.toString()),
				new NameValuePair("txtCensusBlockId",
cdsCensusBlockId.toString()),
				new NameValuePair("txtGenMapImage",
"False"),
				new NameValuePair("txtZoom", "1"),
				new NameValuePair("txtMapWidth", "1"),
				new NameValuePair("txtMapHeight", "1"),
				new NameValuePair("txtInteractiveMap",
"False"),
				// Wait a second, this isn't going to
work...
				new NameValuePair("txtRmTestList",
cdsRmTestList)
		};
//SNIP //

Obviously the above code won't work, but I hope it will illustrate what I'm
trying to achieve.

Thanks!


~Chris


Chris Ashurst
~Systems Production Support
~~Tower Hill Insurance Group




CONFIDENTIAL NOTICE: This email including any attachments, contains 
confidential information belonging to the sender. It may also be 
privileged or otherwise protected by work product immunity or other 
legal rules. This information is intended only for the use of the 
individual or entity named above.  If you are not the intended 
recipient, you are hereby notified that any disclosure, copying, 
distribution or the taking of any action in reliance on the contents 
of this emailed information is strictly prohibited.  If you have 
received this email in error, please immediately notify us by 
reply email of the error and then delete this email immediately.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: NameValuePair Clarification

Posted by sebb <se...@gmail.com>.
Assuming that you can count all the NV pairs you want to send, surely
you can create the array as:

NameValuePair [] nvp = new NameValuePair[count];

and then add the values as indexes 0,1,...count-1 ?

S.
On 31/05/06, Chris Ashurst <CA...@thig.com> wrote:
> I've been looking over the API for NameValuePair, and I've noticed that it
> doesn't seem possible to append new NameValuePairs to an already existing
> set.
>
> This normally isn't a problem, as I guess people know precisely what they're
> going to be sending, but I'm having an issue where I know the majority of
> the variables I'm using in the request, but I have a varying number of
> "flags" that can be sent with a request.
>
> The flags themselves will all have the value of True attached to them, but
> as I say, I can't see a way to extract them from their current state in a
> list and put them into a bunch of NameValuePairs that I can then put into my
> big NameValuePair for the request.
>
> Does the request (in this case, POST) *have* to be in NameValuePair format?
> Can I append extra variables onto the end of the data? I know I must be
> missing something...
>
> // SNIP //
> ListIterator li = cdsRmTestList.listIterator();
>                NameValuePair[] flags = null;
>                while (li.hasNext()) {
>                        flags = new NameValuePair(li.next().toString(),
> "True");
>                }
>                NameValuePair[] data = {
>                                new NameValuePair("txtName",
> cdsName.toString()),
>                                new NameValuePair("txtStreet",
> cdsStreet.toString()),
>                                new NameValuePair("txtCity",
> cdsCity.toString()),
>                                new NameValuePair("txtState",
> cdsState.toString()),
>                                new NameValuePair("txtZip",
> cdsZip.toString()),
>                                new NameValuePair("txtPlus4",
> cdsZipPlusFour.toString()),
>                                new NameValuePair("txtFirm",
> cdsFirm.toString()),
>                                new NameValuePair("txtUserName",
> "towerhilltest"),
>                                new NameValuePair("txtPassword",
> "towerhilltest"),
>                                new NameValuePair("txtLat",
> cdsLat.toString()),
>                                new NameValuePair("txtLon",
> cdsLon.toString()),
>                                new NameValuePair("txtGeoResult",
> cdsGeoResult.toString()),
>                                new NameValuePair("txtCensusBlockId",
> cdsCensusBlockId.toString()),
>                                new NameValuePair("txtGenMapImage",
> "False"),
>                                new NameValuePair("txtZoom", "1"),
>                                new NameValuePair("txtMapWidth", "1"),
>                                new NameValuePair("txtMapHeight", "1"),
>                                new NameValuePair("txtInteractiveMap",
> "False"),
>                                // Wait a second, this isn't going to
> work...
>                                new NameValuePair("txtRmTestList",
> cdsRmTestList)
>                };
> //SNIP //
>
> Obviously the above code won't work, but I hope it will illustrate what I'm
> trying to achieve.
>
> Thanks!
>
>
> ~Chris
>
>
> Chris Ashurst
> ~Systems Production Support
> ~~Tower Hill Insurance Group
>
>
>
>
> CONFIDENTIAL NOTICE: This email including any attachments, contains
> confidential information belonging to the sender. It may also be
> privileged or otherwise protected by work product immunity or other
> legal rules. This information is intended only for the use of the
> individual or entity named above.  If you are not the intended
> recipient, you are hereby notified that any disclosure, copying,
> distribution or the taking of any action in reliance on the contents
> of this emailed information is strictly prohibited.  If you have
> received this email in error, please immediately notify us by
> reply email of the error and then delete this email immediately.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org