views:

62

answers:

3

Currently, I have a servlet act as web service.

When I pass in parameters using POST, it will return me an executable binary file (application/octet-stream). However, beside binary file, I would also like to get additional information (in text format) about this binary file.

Is it possible to achieve this by using only single POST request? But, how is it possible, to switch from application/octet-stream to text/plain within single POST response?

A: 

Within a single POST it isn't possible. But two ideas:

  1. Show your text file as another web page that starts the download of your executable

  2. Bundle both files into a zip archive

sfussenegger
+1  A: 

It is not possible to change the MIME type within a single response.

However, i think t is possible to put your additional information into the response header using the HttpServletResponse.addHeader method.

Sylar
Seem like a hacking way. But I just love this simple solution for my case.
Yan Cheng CHEOK
+1  A: 

You could return a multipart MIME response (multipart/mixed; boundary=XXX instead of application/octet-stream) with the binary part encoded in Base64.

I'm not sure if the JavaMail API can be used to construct the content, but it's worth a look.

McDowell