hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mingfai <mingfai...@gmail.com>
Subject Re: Setting Content Type on a HTTP POST
Date Mon, 19 Jul 2010 23:28:47 GMT
On Tue, Jul 20, 2010 at 4:12 AM, Zachariah Young <zpyoung@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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message