Apache HTTP:如何设置自定义ContentType

时间:2017-06-15 14:06:23

标签: java http mime-types apache-httpclient-4.x apache-httpcomponents

我正在使用apache http客户端将文件上传为

ContentType

问题是服务器端需要文件的application/myCustomTagContentType

但是,这不是ContentType界面中的值。有没有办法让我提供自定义字符串[X-head1: {someJson}, Accept: application/json, X-head2: someVal, X-head3: otherVal, Content-Type: application/json]

修改

我尝试重新创建浏览器上显示的请求

我的请求标题为

[Content-Disposition: form-data; name="file.ext"; filename="test.txt", Content-Type: application/octet-stream, Content-Transfer-Encoding: binary]

和有效载荷

Content-Type: application/myCustomTag

我能看到的关键区别是在有效载荷中我在浏览器中看到以下内容

Content-Type

这不是HTTP标准foreach所以我无法将其设置为

1 个答案:

答案 0 :(得分:1)

您是否在HttpPost上尝试了setHeader? API here

替代:

ContentType.create("应用/ myCustomTag&#34)