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 Amiruddin Nagri <am...@gmail.com> on 2010/05/21 17:52:46 UTC
Sending JSON string in post body
Hi,
I need to send a JSON string in the body of a post request.
The json is going to be a string in the place of body. Since the interface
to send paramters in post request is name/value based, is there any way I
can send a string in the body of this request.
Regards,
Amiruddin Nagri,
Bangalore, 560008, KA
India
Y! IM : amir_nagri@yahoo.com
GTalk : amir.nagri@gmail.com
Re: Sending JSON string in post body
Posted by Florent Blondeau <fb...@pingwy.com>.
Hi,
I use that pretty extensively to test some web services that need to
receive post request with JSON strings:
/**
* Sends a JSON string to a specific URL and returns the plain
response of the server
*/
public String sendToWebService(String url, String jsonString){
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
post.setHeader("Content-Type", "application/json");
post.setEntity(new StringEntity(jsonString,"UTF-8"));
ResponseHandler<String> responseHandler = new
BasicResponseHandler();
String response = httpClient.execute(post,responseHandler);
return response;
}
Hope that helps
Florent
Pingwy
27, rue des arènes
49100 Angers
Amiruddin Nagri a écrit :
> Hi,
>
> I need to send a JSON string in the body of a post request.
>
> The json is going to be a string in the place of body. Since the interface
> to send paramters in post request is name/value based, is there any way I
> can send a string in the body of this request.
>
> Regards,
> Amiruddin Nagri,
> Bangalore, 560008, KA
> India
>
> Y! IM : amir_nagri@yahoo.com
> GTalk : amir.nagri@gmail.com
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org