tags:

views:

433

answers:

3

I have a HTTP GET request that I am attempting to send. I tried adding the parameters to this request by first creating a BasicHttpParams object and adding the parameters to that object, then calling setParams( basicHttpParms ) on my HttpGet object. This method fails. But if I manually add my parameters to my URL (i.e. append '?param1=value1&param2=value2') it succeeds.

I know I'm missing something here and any help would be greatly appreciated.

Thanks in advance,

groomsy

+1  A: 

hi groomsy

The method

setParams() 

like

httpget.getParams().setParameter("http.socket.timeout", new Integer(5000));

only adds HttpProtocol parameters.

To execute the httpGet you should append your parameters to the url manually

HttpGet myGet = new HttpGet("http://foo.com/someservlet?param1=foo&param2=bar");

or use the post request the difference between get and post requests are explained here, if you are interested http://www.cs.tut.fi/~jkorpela/forms/methods.html

gabe
Thank you for your help. I thought there might be a more effective way of adding parameters to GET requests.
groomsy
A: 

Hi.

To build uri with get parameters, Uri.Builder provides a more effective way.

new Uri.Builder()
    .scheme("http")
    .authority("foo.com")
    .path("someservlet")
    .appendQueryParameter("param1", foo)
    .appendQueryParameter("param2", bar)
    .build();
9re