On Tue, 2010-07-20 at 07:28 +0800, Mingfai wrote:
> On Tue, Jul 20, 2010 at 4:12 AM, Zachariah Young <[email protected]> wrote:
>
> > Where should I be setting the Content Type when I'm posting and XML string?
> >
> > HttpPost httppost = new HttpPost("http://localhost:8080/REST");
> > // Make sure the server knows what kind of a response we will accept
> > httppost.addHeader("Accept", "text/xml");
> >
>
> this is the right place to set the header.
>
>
>
> > // Also be sure to tell the server what kind of content we are sending
> > httppost.addHeader("Content-Type", "application/xml");
> >
>
> you technically could set this header but it is normally not a valid request
> header. "Content-Type" is used in http response rather than request.
>
>
"Content-Type" is perfectly valid for all types of entity enclosing
messages.
>
> >
> > or
> >
> > StringEntity stringEntity = new
> >
> > StringEntity("<printparamaters><request>1</request></printparamaters>","UTF-8");
> > stringEntity.setContentType("application/xml");
> >
> >
> i don't think the entity content type will affect the http request headers
> at all.
>
Actually it will. Setting content-type on the entity is in fact
recommended.
Cheers
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]