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 Kevin Roll <kr...@appropel.com> on 2009/07/02 15:40:24 UTC
Request parameters?
I'm trying to use httpclient-4.0-beta2 to achieve what seems like a
simple thing. I want to make a request to a certain URL with a set of
parameters. My code looks like this:
HttpParams params = new BasicHttpParams();
params.setParameter("someparam", "somevalue");
HttpClient httpClient = new DefaultHttpClient();
HttpUriRequest httpGet = new HttpGet("http://www.someserver.com/
servlet");
httpGet.setParams(params);
HttpResponse response = httpClient.execute(httpGet);
So, I would expect that a URL would be generated that looks like
http://www.someserver/com/servlet?someparam=somevalue
No matter what I do it seems that my parameters are ignored, causing
an error response from the server. Surprisingly none of the examples
cover this simple case. Am I doing something obviously wrong here?
Thanks!
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Request parameters?
Posted by Kevin Roll <kr...@appropel.com>.
On Jul 2, 2009, at 10:18 AM, Oleg Kalnichevski wrote:
> Please see Fundamentals section of the HttpClient tutorial:
> http://wiki.apache.org/HttpComponents/HttpClientTutorial
Perfect. Thank you, Oleg!
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Request parameters?
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, Jul 02, 2009 at 10:13:35AM -0400, Kevin Roll wrote:
>
> On Jul 2, 2009, at 10:09 AM, Oz Levanon wrote:
>
>> I'm not using httpclient version 4, so I couldn't compile your code,
>> but
>> it seems to me your confusing two different types of parameters.
>> The parameter you want are the URL parameters. To send them simply add
>> your data to the URL you create (taking care to put "?" before the
>> first
>> parameter and "&" before subsequent parameters). For example:
>>
>> HttpUriRequest httpGet = new
>> HttpGet("http://www.someserver.com/servlet?parm1=value1&parm2=value2&par
>> m3=value3");
>
>
> I thought that might be the case, but then what's the point of using
> HttpClient? I'm looking for an abstraction of this complexity, and if
> it's not provided I'm rather frustrated (I've already spent hours on
> this).
>
Please see Fundamentals section of the HttpClient tutorial:
http://wiki.apache.org/HttpComponents/HttpClientTutorial
Oleg
> By way of comparison, this fragment was originally written using
> HttpUnit. The code is almost identical, but in that case the URL gets
> constructed the way I expect and I get the proper results. I can't use
> HttpUnit any more due to a jar file conflict, so I'm looking for other
> solutions...
>
> Thanks for the reply, Oz.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Request parameters?
Posted by Kevin Roll <kr...@appropel.com>.
On Jul 2, 2009, at 10:09 AM, Oz Levanon wrote:
> I'm not using httpclient version 4, so I couldn't compile your code,
> but
> it seems to me your confusing two different types of parameters.
> The parameter you want are the URL parameters. To send them simply add
> your data to the URL you create (taking care to put "?" before the
> first
> parameter and "&" before subsequent parameters). For example:
>
> HttpUriRequest httpGet = new
> HttpGet("http://www.someserver.com/servlet?parm1=value1&parm2=value2&par
> m3=value3");
I thought that might be the case, but then what's the point of using
HttpClient? I'm looking for an abstraction of this complexity, and if
it's not provided I'm rather frustrated (I've already spent hours on
this).
By way of comparison, this fragment was originally written using
HttpUnit. The code is almost identical, but in that case the URL gets
constructed the way I expect and I get the proper results. I can't use
HttpUnit any more due to a jar file conflict, so I'm looking for other
solutions...
Thanks for the reply, Oz.
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
RE: Request parameters?
Posted by Oz Levanon <Oz...@mobixell.com>.
I'm not using httpclient version 4, so I couldn't compile your code, but
it seems to me your confusing two different types of parameters.
The parameter you want are the URL parameters. To send them simply add
your data to the URL you create (taking care to put "?" before the first
parameter and "&" before subsequent parameters). For example:
HttpUriRequest httpGet = new
HttpGet("http://www.someserver.com/servlet?parm1=value1&parm2=value2&par
m3=value3");
I believe the parameters you set in the code below (I could be wrong,
since I don't have access to the code) are HTTP Connection Parameters,
which are parameters that are passed on the HTTP connection (e.g.
"host", "user-agent", etc.) and can be seen by sniffing the traffic
(using WireShark, or tcpdump, for example).
Please also note that parameters in the request must be escaped, i.e.
you must replaced any special characters (e.g. %) with an escaping
sequence, so that the parser won't confuse them with the special
character's function (see
http://www.blooberry.com/indexdot/html/topics/urlencoding.htm)
HTH,
Oz
-----Original Message-----
From: Kevin Roll [mailto:kroll@appropel.com]
Sent: Thursday, July 02, 2009 4:40 PM
To: httpclient-users@hc.apache.org
Subject: Request parameters?
I'm trying to use httpclient-4.0-beta2 to achieve what seems like a
simple thing. I want to make a request to a certain URL with a set of
parameters. My code looks like this:
HttpParams params = new BasicHttpParams();
params.setParameter("someparam", "somevalue");
HttpClient httpClient = new DefaultHttpClient();
HttpUriRequest httpGet = new HttpGet("http://www.someserver.com/
servlet");
httpGet.setParams(params);
HttpResponse response = httpClient.execute(httpGet);
So, I would expect that a URL would be generated that looks like
http://www.someserver/com/servlet?someparam=somevalue
No matter what I do it seems that my parameters are ignored, causing
an error response from the server. Surprisingly none of the examples
cover this simple case. Am I doing something obviously wrong here?
Thanks!
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org