Tomcat httpclient:通过https将HttpResponse复制到HttpServletResponse

Tomcat httpclient:通过https将HttpResponse复制到HttpServletResponse,tomcat,servlets,httpclient,httpresponse,Tomcat,Servlets,Httpclient,Httpresponse,我有下面的代码将httpresponse转换为httpservletresponse,如果通过http URL访问服务器,它工作得很好,但不能通过https工作 问题是,如果URL是HTTPs,我从httpservletresponse获取空字符串 public void extractResponse(HttpResponse httpResponse, HttpServletResponse response) { InputStream inputStream = null;

我有下面的代码将httpresponse转换为httpservletresponse,如果通过http URL访问服务器,它工作得很好,但不能通过https工作

问题是,如果URL是HTTPs,我从httpservletresponse获取空字符串

public void extractResponse(HttpResponse httpResponse, HttpServletResponse response)
{
    InputStream inputStream = null;
    try {
        inputStream = httpResponse.getEntity().getContent();


        String responseStr = EntityUtils.toString(httpResponse.getEntity());  //Get the contect from httpresponse, it has the value I want


        copyStream(inputStream, response.getOutputStream());
    } catch (IllegalStateException | IOException e) {
    }
    finally{
        if(inputStream != null)
        {
            try {
                inputStream.close();
            } catch (IOException e) {
            }
        }
    }
}

/**
 * Wrapper for IOUtils.copy
 * @param input
 * @param output
 * @throws IOException
 */
public void copyStream(InputStream input, OutputStream output) throws IOException
{
    IOUtils.copy(input, output);
}

仅供参考,我在两台服务器上都使用tomcat,httpclient的版本是4.13。

我自己解决了这个问题,这个问题是由两台服务器之间的HTTP模式不一致引起的

例如,如果您在服务器A中使用HTTPClient创建HTTP请求,请求将发送到服务器B,如果您使用HTTP模式(URL将为“”)访问服务器A,则在创建HTTP请求时必须使用相同的HTTP模式,另一方面,如果您在服务器A中使用HTTPS,您必须使用HTTPS访问服务器B,否则,它将永远无法工作

一旦您确认了一致的HTTP模式,我在问题上发布的代码就会起作用