0

我想向 Web 服务发出请求,该服务将根据请求参数返回图像?对此最好的方法是什么?

4

2 回答 2

5

只需制作一个 Servlet 服务图像,将参数传递给它基于参数的处理图像并作为响应返回,这将作为一个 REST Web 服务,您也可以使用一些标准的 Web 服务实现来实现这一点


还要检查

于 2012-08-28T08:22:28.847 回答
1

By web service you mean something in the web, or a Web Service using SOAP over HTTP?

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).

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. Or... if you need also the content-type, return a structure with content-type: string and data: byte[].

于 2012-08-28T08:24:24.617 回答