在multipart实体中添加content-id标头

时间:2017-09-06 13:17:47

标签: java rest http apache-httpclient-4.x

我正在尝试使用Java HttpClient和实体mime类发送多部分请求。请求如下:

POST /webservices/picture/7 HTTP/1.1
Host: abc.def
Content-Type: multipart/related; boundary=random_boundary_data;
 start="<49f75f79-c221-493c-a5f7-307c37f35828>"

--random_boundary_data
Content-Type: application/json;charset=UTF-8
Content-ID: <49f75f79-c221-493c-a5f7-307c37f35828>

{
    "type": "BASIC",
    "pictureId": {
        "uri": "cid:E6626568-4749-4FAC-85E0-B475C048FFB6"
    }
}
--random_boundary_data
Content-Type: image/jpeg
Content-ID: <E6626568-4749-4FAC-85E0-B475C048FFB6>

<<binary-image-data>>
--random_boundary_data

我在使用MultipartEntityBuilder在实体中设置Content-ID标头时遇到问题。

HttpEntity entity = MultipartEntityBuilder
                .create()
                .addTextBody("pic_json", picObj.toJSONString(), ContentType.create("application/json"))
                .addBinaryBody("upload_file", upIcon, ContentType.create("image/jpeg"), "filename")
                .build();


        HttpPost httpPost = new HttpPost("https://" + ipaddr + "/" + picUri);
        httpPost.setEntity(entity);
        httpPost.setHeader("Content-Type", "multipart/related");

0 个答案:

没有答案