hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Xinjun Chen" <xjchen...@gmail.com>
Subject Re: [HttpClient 3.0.1] cannot set Content-Type when using MultipartRequestEntity
Date Tue, 15 May 2007 05:03:41 GMT
Hi Roland,

Do you mean I should create another RequestEntity class to extend the
current MultipartRequestEntity and override the getContentType() method?

>From the getContentType() method, we can find that the contentType is fixed
to be "multipart/form-data". What if I setContentType to the post method
explicitly? Will it take any effect?

I have written some code for this task. My codes look ok but just doesn't
work. I have the following specific questions regarding using HttpClient to
achieve the purpose of sending SOAP with attachment files:

1. SOAP part:

         StringPart soapPart = new StringPart("soapPart", soapRequest);
         soapPart.setContentType("text/xml");
         soapPart.setCharSet(null);

What kind of CharSet should I use? When I use XML Exchanger to send an HTTP
request with SOAP and attachment files, the charset is not set in soapPart
or filePart. However, HttpClient by default add ISO-8859-1 as charset. Is it
compulsary for me to setCharSet as null?

2. Http contentType:
Before executing post method, I set the content type as follows:

post.setRequestHeader("Content-Type", "multipart/related; boundary=" +
soapPart.getBoundary());

But the effect is that the Http body is lost inspecting from TCPMonitor.


 By the way, I searched the HttpClient documentations and samples from
Apache website, but could not find information about sending SOAP with
attachment files. I think this task should be quite common. If possible,
could you give me some pointer to that?


Regards,
Xinjun


On 5/14/07, Roland Weber <ROLWEBER@de.ibm.com> wrote:
>
> Hello Xinjun,
>
> > I constructed a PostMethod and set MultipartRequestEntity. I put the
> > SOAPRequest as a StringPart, and the attachment as a FilePart.
> HttpClient
> > does not generate the desired MIME Request. I want to specify the
> StringPart
> > content-type as "text/xml; charset=UTF-8", but HttpClient just generated
> > "text/plain; charset=US-ASCII" even if I explicitly set content-type
> header.
>
> You can override MultipartRequestEntity.getContentType() to specify
> the value for the Content-Type header. An explicitly set header will
> be overwritten.
>
> hope that helps,
> Roland
>
>

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