pokeRex110 pokeRex110 - 1 month ago 9
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");
post.setParams(params);
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
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));
httpClient.execute(httpPost);
Comments