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 smith jack <th...@gmail.com> on 2011/07/16 09:57:59 UTC

How to set the parameters if i want to use HttpPost

the httpclient i use is of version 4.0, the document seems to be
obselete, as a example, i can no longer use the following code now,
what change i should make in order to use httppost using httpclient
4.0

List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("param1", "value1"));
formparams.add(new BasicNameValuePair("param2", "value2"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
HttpPost httppost = new HttpPost("http://localhost/handler.do");
httppost.setEntity(entity);    // HttpPost now has no API named
setEntity    -_____-

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


Re: How to set the parameters if i want to use HttpPost

Posted by Jon Moore <jo...@jjmoore.net>.
Note that HttpRequest doesn't have a setEntity(); you might see your problem below if you've declared it like this:

HttpRequest post = new HttpPost(...);

(Confession: I do this all the time). Use either:

HttpPost post = new HttpPost(...);

or

HttpEntityEnclosingRequest post = new HttpPost();

Was that your issue?

Jon
........
Jon Moore


On Jul 16, 2011, at 3:05 PM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Sat, 2011-07-16 at 15:57 +0800, smith jack wrote:
>> the httpclient i use is of version 4.0, the document seems to be
>> obselete, as a example, i can no longer use the following code now,
>> what change i should make in order to use httppost using httpclient
>> 4.0
>> 
>> List<NameValuePair> formparams = new ArrayList<NameValuePair>();
>> formparams.add(new BasicNameValuePair("param1", "value1"));
>> formparams.add(new BasicNameValuePair("param2", "value2"));
>> UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
>> HttpPost httppost = new HttpPost("http://localhost/handler.do");
>> httppost.setEntity(entity);    // HttpPost now has no API named
>> setEntity    -_____-
>> 
> 
> 
> It is still there.
> 
> http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/methods/HttpPost.html
> http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpEntityEnclosingRequest.html#setEntity%28org.apache.http.HttpEntity%29
> 
> Oleg
> 
> 
> ---------------------------------------------------------------------
> 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: How to set the parameters if i want to use HttpPost

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Sat, 2011-07-16 at 15:57 +0800, smith jack wrote:
> the httpclient i use is of version 4.0, the document seems to be
> obselete, as a example, i can no longer use the following code now,
> what change i should make in order to use httppost using httpclient
> 4.0
> 
> List<NameValuePair> formparams = new ArrayList<NameValuePair>();
> formparams.add(new BasicNameValuePair("param1", "value1"));
> formparams.add(new BasicNameValuePair("param2", "value2"));
> UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
> HttpPost httppost = new HttpPost("http://localhost/handler.do");
> httppost.setEntity(entity);    // HttpPost now has no API named
> setEntity    -_____-
> 


It is still there.

http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/methods/HttpPost.html
http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpEntityEnclosingRequest.html#setEntity%28org.apache.http.HttpEntity%29

Oleg


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