pokeRex110 pokeRex110 - 1 year ago 100
Java Question

Adding parameter to HttpPost on Apache's httpclient

I am trying to set some Http parameters in the HttpPost object.

HttpPost post=new HttpPost(url);
HttpParams params=new BasicHttpParams();
params.setParameter("param", "value");
HttpResponse response = client.execute(post);

It looks like the parameter is not set at all. Do you have any idea why this is happening?

Thank you

Answer Source
HttpPost httpPost = new HttpPost(url);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("param", "value");
httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download