[英]Return an image from webservice
I want to make request to a web service which will return an image based on request parameter? 我想向Web服务发出请求,该服务将基于请求参数返回图像? What is the best possible approach for this?
最好的方法是什么?
Simply make a Servlet serving image, pass the parameter to it process image based on param and return as a response, This would serve as a rest web service, You could also go for some standard implementation of webservice to achieve this 只需制作一个Servlet服务映像,然后根据参数将参数传递给它来处理映像,然后作为响应返回即可,这将作为其余的Web服务,您也可以通过一些标准的Webservice实现来实现
Also Check 同时检查
By web service you mean something in the web, or a Web Service using SOAP over HTTP? Web服务是指Web中的某些东西,还是使用基于HTTP的SOAP的Web服务?
If it's the first thing I should write a Servlet that depending on request parameters write the bytes of the image to the output stream (setting appropiate headers like Content-Type). 如果是第一件事,我应该编写一个Servlet,根据请求参数将图像的字节写入输出流(设置适当的标头,例如Content-Type)。
doGet(...) {
request.setContentHeader("Content-Type", "image/jpeg");
// write image bytes to request.getOutputStream()
...
}
If it's the second thing simply return a byte[] with the content. 如果是第二件事,只需返回包含内容的byte []。 Or... if you need also the content-type, return a structure with
content-type: string
and data: byte[]
. 或者...如果还需要content-type,则返回一个具有
content-type: string
和data: byte[]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.