简体   繁体   English

Apache HttpClient PostMan

[英]Apache HttpClient PostMan

When using the apache.HttpClient to send a multipart, I generate the following output as below: 当使用apache.HttpClient发送一个多部分时,我生成以下输出:

18:29:58.800 DEBUG nnnweServiceImpl - 18:29:58.800 DEBUG nnnweServiceImpl-

--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. 但这似乎因500内部服务器错误而失败,而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"? 所以我的问题是,我可以使用“ apache.httpclient”删除java中的字符集和内容传输编码吗? 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?) (为什么邮递员不显示我发送的xml文件?)

Make sure to use the so called 'lax' mode when generating multipart mime entities with Apache HttpClient 使用Apache HttpClient生成多部分mime实体时,请确保使用所谓的“宽松”模式

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM