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 khiem nguyen <kh...@googlemail.com> on 2011/06/29 10:15:45 UTC

null/empty value in request string

hi
i have a post request like this:

param1=value1&param2=&param3=value3

if i put these into a ArrayList<NameValuePair> for a POST, should the value
of param2 an empty-string or should it be null ? does defaultHttpClient
handle these 2 cases differently ?

thanx

cheers

Re: null/empty value in request string

Posted by khiem nguyen <kh...@googlemail.com>.
ok, thanx alot for the explaination

On Wed, Jun 29, 2011 at 7:52 PM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Wed, 2011-06-29 at 10:15 +0200, khiem nguyen wrote:
> > hi
> > i have a post request like this:
> >
> > param1=value1&param2=&param3=value3
> >
> > if i put these into a ArrayList<NameValuePair> for a POST, should the
> value
> > of param2 an empty-string or should it be null ? does defaultHttpClient
> > handle these 2 cases differently ?
> >
> > thanx
> >
> > cheers
>
> Khiem,
>
> HttpClient handles treats empty and null parameter values the same
>
> List<NameValuePair> nvps = new ArrayList<NameValuePair>();
> nvps.add(new BasicNameValuePair("p1", ""));
> nvps.add(new BasicNameValuePair("p2", null));
> System.out.println(URLEncodedUtils.format(nvps, HTTP.ASCII));
>
> > p1=&p2=
>
> Hope this helps
>
> Oleg
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

Re: null/empty value in request string

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2011-06-29 at 10:15 +0200, khiem nguyen wrote:
> hi
> i have a post request like this:
> 
> param1=value1&param2=&param3=value3
> 
> if i put these into a ArrayList<NameValuePair> for a POST, should the value
> of param2 an empty-string or should it be null ? does defaultHttpClient
> handle these 2 cases differently ?
> 
> thanx
> 
> cheers

Khiem,

HttpClient handles treats empty and null parameter values the same

List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("p1", ""));
nvps.add(new BasicNameValuePair("p2", null));
System.out.println(URLEncodedUtils.format(nvps, HTTP.ASCII));

> p1=&p2=

Hope this helps

Oleg 



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