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 Zachariah Young <zp...@gmail.com> on 2010/07/19 22:12:18 UTC
Setting Content Type on a HTTP POST
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");
// Also be sure to tell the server what kind of content we are sending
httppost.addHeader("Content-Type", "application/xml");
or
StringEntity stringEntity = new
StringEntity("<printparamaters><request>1</request></printparamaters>","UTF-8");
stringEntity.setContentType("application/xml");
--
Zachariah Young
http://zachariahyoung.com
zpyoung@gmail.com
(479) 966-9169
Re: Setting Content Type on a HTTP POST
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2010-07-20 at 07:28 +0800, Mingfai wrote:
> On Tue, Jul 20, 2010 at 4:12 AM, Zachariah Young <zp...@gmail.com> 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: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Setting Content Type on a HTTP POST
Posted by Mingfai <mi...@gmail.com>.
On Tue, Jul 20, 2010 at 4:12 AM, Zachariah Young <zp...@gmail.com> 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.
>
> 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.
regards,
mingfai