dotmindlabs
dotmindlabs

Reputation: 908

Apache HttpClient PostMan

When using the apache.HttpClient to send a multipart, I generate the following output as below:

18:29:58.800 DEBUG n.n.n.w.e.ServiceImpl -

--bEDi1DhmFcmCTebUvLowWpRtw-OscIydQ24RSB
Content-Disposition: form-data; name="id"
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

ChecknLoadEnvironmentData
--bEDi1DhmFcmCTebUvLowWpRtw-OscIydQ24RSB
Content-Disposition: form-data; name="file"; filename="myfile.xml"
Content-Type: text/xml; charset=ISO-8859-1
Content-Transfer-Encoding: binary

<?xml version="1.0" encoding="ISO-8859-1" ?>
<Dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ImportProgramVersion>3.1</ImportProgramVersion> 
    <Year>2012</Year> 
    ....
    .... 
</Dataset>
--bEDi1DhmFcmCTebUvLowWpRtw-OscIydQ24RSB--

But this seems to fail with a 500 internal server error and it succeeds with PostMan.

----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="id"

ChecknLoadEnvironmentData
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="filename"

myXML.xml
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="file"; filename="myXML.xml"
Content-Type: text/xml


----WebKitFormBoundaryE19zNvXGzXaLvS5C

So my question is, can I remove the charset and content-transfer-encoding in java with "apache.httpclient"? So I can eliminate the differences between the two requests. I looked into the library source and does not seem to be possible, it will always default to some value.

(Why does Postman not display my sending xml file?)

Upvotes: 0

Views: 1612

Answers (1)

ok2c
ok2c

Reputation: 27623

Make sure to use the so called 'lax' mode when generating multipart mime entities with Apache HttpClient

http://hc.apache.org/httpcomponents-client-4.3.x/httpmime/apidocs/org/apache/http/entity/mime/MultipartEntityBuilder.html#setLaxMode()

Upvotes: 0

Related Questions