HTTPS的代理Servlet [英] Proxy Servlet for HTTPS

查看:104
本文介绍了HTTPS的代理Servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个安全的网站,需要在某些网页上显示来自外部非https网址的图片。我想创建一个仅用作代理的servlet,将图像数据传递给页面。一种方法是使用Apache的HttpClient下载图像数据,然后使用IOUtils.copy将数据复制到servlet的响应中。

I have a secure site that needs to display images coming from external non-https URLs on certain pages. I want to create a servlet that is used only as a proxy to pass the image data to the pages. 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.

有更简单的方法吗?

更新:原因是避免浏览器警告。

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.

这篇关于HTTPS的代理Servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆