Multipart requests/responses java

2019-01-20 13:02发布

问题:

I have a task to implement sending of http multipart request and interpreting http multipart response. I decided to start from the response as I just have to receive a response and parse it. I have not that much experience with java and even less with HTTP and that is why I read some articles and other stuff on the topic but I have still some open questions:

  1. As far as I understood the content type multipart is used for file upload, sending email attachments, etc. The most posts that I found in google were actully for file upload using multipart/form-data. In what other cases is this content-type used?
  2. I decided to start with the HTTP multipart response, but I realised I have no idea what I have to do in order to receive a response with such a content type. How shall my request look like, what shall I request with this request? I just want to write a simple program in java, which sends an HTTP request to a server and the response that is received is with content-type multipart.

It would be nice if someone can clarify these things to me because I think I have misunderstood something.

Thank you in advance!

回答1:

I would recommend turning to Apache Commons:

  • FileUpload handles the server-side, and parses multi-part posts.
  • HttpClient for the client-side, for constructing those posts.

But before you do any of that, I think you need to talk with whoever has set you on this task, to be sure that you understand exactly what he/she wants. Because multi-part for mail processing is close but not quite the same as multipart for file uploads.