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 "Nation, Carey" <Ca...@turner.com> on 2010/10/15 18:11:44 UTC

How do I set the request body for an HttpPost in 4.x

I'm sure this is obvious and I'm sure I just didn't ask google the
proper question, but I'm stumped.

 

I need to post a big blob of xml to a servlet.  The xml needs to be in
the request body.  In 3.x you said something like req.setBody( string).
I can't find anything like that in 4.x.  I just need it to end up:

 

Content-type: text/xml

Content-length: yourLengthHere

 

<xml />

 

Thanks!

 

 

________________________________

Carey Nation <ma...@cnn.com> 
Lead Software Engineer
CNN BEST
Broadcast Production Systems
Video Solutions Group
(404)827-2935 (wk)
(404)824-0033 (cell) 

________________________________


Re: How do I set the request body for an HttpPost in 4.x

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2010-10-15 at 12:11 -0400, Nation, Carey wrote:
> I'm sure this is obvious and I'm sure I just didn't ask google the
> proper question, but I'm stumped.
> 
>  
> 
> I need to post a big blob of xml to a servlet.  The xml needs to be in
> the request body.  In 3.x you said something like req.setBody( string).
> I can't find anything like that in 4.x.  I just need it to end up:
> 
>  
> 
> Content-type: text/xml
> 
> Content-length: yourLengthHere
> 
>  
> 
> <xml />
> 
>  
> 
> Thanks!
> 

Please take a look at

http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d4e164

Oleg



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


RE: How do I set the request body for an HttpPost in 4.x

Posted by "Nation, Carey" <Ca...@turner.com>.
Anil and Oleg thanks!  That fixed it!

-----Original Message-----
From: Anil Pathak [mailto:anil@aniljava.com] 
Sent: Friday, October 15, 2010 6:33 PM
To: HttpClient User Discussion
Subject: Re: How do I set the request body for an HttpPost in 4.x

One way to use is StringBody

http://hc.apache.org/httpcomponents-client-ga/download.html

        HttpClient client = new DefaultHttpClient();


        MultipartEntity entity = new
MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        entity.addPart("xml", new StringBody("YOUR XML DATA"));

        HttpPost post = new HttpPost(url);
        post.setEntity(entity);

~Anil












On Fri, Oct 15, 2010 at 11:11 AM, Nation, Carey
<Ca...@turner.com>wrote:

> I'm sure this is obvious and I'm sure I just didn't ask google the 
> proper question, but I'm stumped.
>
>
>
> I need to post a big blob of xml to a servlet.  The xml needs to be in

> the request body.  In 3.x you said something like req.setBody(
string).
> I can't find anything like that in 4.x.  I just need it to end up:
>
>
>
> Content-type: text/xml
>
> Content-length: yourLengthHere
>
>
>
> <xml />
>
>
>
> Thanks!
>
>
>
>
>
> ________________________________
>
> Carey Nation <ma...@cnn.com> Lead Software Engineer CNN 
> BEST Broadcast Production Systems Video Solutions Group
> (404)827-2935 (wk)
> (404)824-0033 (cell)
>
> ________________________________
>
>

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


Re: How do I set the request body for an HttpPost in 4.x

Posted by Anil Pathak <an...@aniljava.com>.
One way to use is StringBody

http://hc.apache.org/httpcomponents-client-ga/download.html

        HttpClient client = new DefaultHttpClient();


        MultipartEntity entity = new
MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        entity.addPart("xml", new StringBody("YOUR XML DATA"));

        HttpPost post = new HttpPost(url);
        post.setEntity(entity);

~Anil












On Fri, Oct 15, 2010 at 11:11 AM, Nation, Carey <Ca...@turner.com>wrote:

> I'm sure this is obvious and I'm sure I just didn't ask google the
> proper question, but I'm stumped.
>
>
>
> I need to post a big blob of xml to a servlet.  The xml needs to be in
> the request body.  In 3.x you said something like req.setBody( string).
> I can't find anything like that in 4.x.  I just need it to end up:
>
>
>
> Content-type: text/xml
>
> Content-length: yourLengthHere
>
>
>
> <xml />
>
>
>
> Thanks!
>
>
>
>
>
> ________________________________
>
> Carey Nation <ma...@cnn.com>
> Lead Software Engineer
> CNN BEST
> Broadcast Production Systems
> Video Solutions Group
> (404)827-2935 (wk)
> (404)824-0033 (cell)
>
> ________________________________
>
>