HttpClient 4.5 中转请求到HttpServletResponse

通过httpclient发送请求到其它资源,把请求响应的内容转给httpServletResponse

public void testData(HttpServletResponse response) {
        HttpResponse httpResponse = null;
        try {
            // 请求外部资源
            httpResponse = Request.Get(url).connectTimeout(30000).execute().returnResponse();
            HttpEntity entity = httpResponse.getEntity();
            // 这里还可以设置响应头
            //  把外部资源响应的内容传到HttpServletResponse中去
            entity.writeTo(response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

你可能感兴趣的:(HttpClient 4.5 中转请求到HttpServletResponse)