hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Florent Blondeau <fblond...@pingwy.com>
Subject Re: Sending JSON string in post body
Date Fri, 21 May 2010 16:15:56 GMT

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 
        String response = httpClient.execute(post,responseHandler);
        return response;

Hope that helps


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

View raw message