简体   繁体   English

HTTPS的代理Servlet

[英]Proxy Servlet for HTTPS

I have a secure site that needs to display images coming from external non-https URLs on certain pages. 我有一个安全的网站,需要在某些页面上显示来自外部非https URL的图像。 I want to create a servlet that is used only as a proxy to pass the image data to the pages. 我想创建一个仅用作将图像数据传递到页面的代理的servlet。 One way is to use Apache's HttpClient to download the image data and then use IOUtils.copy to copy the data to the servlet's response. 一种方法是使用Apache的HttpClient下载图像数据,然后使用IOUtils.copy将数据复制到servlet的响应中。

Is there a simpler way? 有没有更简单的方法?

UPDATE: The reason for this is to avoid browser warnings. 更新:这样做的原因是为了避免浏览器警告。

This is what I ended up using: 我最终使用的是:

    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        try {
            String url = request.getParameter("url");
            HttpClient httpClient = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(url);
            HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            InputStream inputStream = httpEntity.getContent();
            response.setContentType("image/jpeg");
            IOUtils.copy(inputStream, response.getOutputStream());
        } catch (Exception e) {
            AppLogger.log(e);
        }
    }

If anyone has a better way to accomplish this, please post it. 如果有人有更好的方法来完成此操作,请发布它。

如果我了解得很好,则您不需要这样的东西,只需返回对图像或音频的引用,或HTML响应中的其他任何内容,浏览器就会处理向包含每个资源的服务器发出的请求,如果可以访问,它们将显示在客户端上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM