1
votes

I've got a small piece of code which submits an XML entity along with binary data in the same POST. I'm using the httpclient and httpmime for this.

I'm not quite sure if I should set the Content-Type header for this request. After all, the Content-Type is both application/xml and application/octet-stream.

What's the correct usage for this?

    post = new HttpPost(uri);
    post.setHeader("Authorization", auth);

    // Should I set Content-Type at all?
    post.setHeader("Content-Type", mimeType + ";charset=UTF-8");

    MultipartEntityBuilder b = MultipartEntityBuilder.create();
    b.addTextBody("data", payload, ContentType.APPLICATION_XML);
    b.addBinaryBody("file", file);
    post.setEntity(b.build());
1

1 Answers

1
votes

No, you should not. You should let HttpClient generate Content-Type as well as other content metadata headers automatically based on properties of the message entity.