Is there a java utility to produce http multi-part responses?

梦想的初衷 提交于 2019-12-21 13:06:07

问题


I am building a web-service that returns a multipart response. I know the format for constructing a multi-part response; and I will build my own tools if I can't find existing tools.

Perhaps I just need help with my google-foo. Everything I find is about POSTing or consuming multi-part messages. Nothing about producing multi-part responses.


回答1:


You can use oreilly servlets http://www.servlets.com/cos/

An example is in the javadoc: http://www.servlets.com/cos/javadoc/com/oreilly/servlet/MultipartResponse.html

import com.oreilly.servlet.MultipartResponse

//javax.servlet.http.HttpServletResponse res
MultipartResponse multi = new MultipartResponse(res);

multi.startResponse("text/plain");
out.println("On your mark");
multi.endResponse();

try { Thread.sleep(1000); } catch (InterruptedException e) { }

multi.startResponse("text/plain");
out.println("Get set");
multi.endResponse();

try { Thread.sleep(1000); } catch (InterruptedException e) { }

multi.startResponse("image/gif");
ServletUtils.returnFile(req.getRealPath("/images/go.gif"), out);

multi.finish();



回答2:


Have you tried the Apache HttpClient project? I haven't looked at it since it broke out from the Apache Commons stuff, but I know it did a lot with multi-part responses.

This is for consuming - not sure if there is anything for producing, but it might be a place to start.

http://hc.apache.org/httpclient-3.x/methods/multipartpost.html



来源:https://stackoverflow.com/questions/4808806/is-there-a-java-utility-to-produce-http-multi-part-responses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!