首页 > 解决方案 > 如何从 apache http 客户端响应中删除服务器/软件信息

问题描述

我写了下面的示例程序来检查http的响应

    public class CloseableHttpClientExmpl {

    public static void main(String[] args) {
        CloseableHttpClient client =HttpClients.custom().disableContentCompression().build();
        HttpGet request = new HttpGet("http://localhost:8080/index.php");
        CloseableHttpResponse response=null;
        try {
            response = client.execute(request);
            System.out.println(response);
        } catch (ClientProtocolException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}

输出/响应如下

HttpResponseProxy{HTTP/1.1 200 OK [Date: Thu, 11 Apr 2019 12:48:38 GMT, Server: Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.8, X-Powered-By: PHP/7.0.8, Content-Length: 79, Keep-Alive: timeout=5, max=99, Connection: Keep-Alive, Content-Type: text/html; charset=UTF-8] ResponseEntityProxy{[Content-Type: text/html; charset=UTF-8,Content-Length: 79,Chunked: false]}}

现在我想知道如何从该响应中删除如下软件信息

Server: Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.8, X-Powered-By: PHP/7.0.8

标签: javaxamppapache-httpclient-4.xapache-httpcomponentsapache-httpclient-5.x

解决方案


下面提到的服务器详细信息由服务器发送,即在您的情况下为 localhost。

Server: Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.8, X-Powered-By: PHP/7.0.8

您可以在服务器配置中禁用作为响应的一部分发送的“服务器”详细信息。对于 Windows 服务器,使用https://www.saotn.org/remove-iis-server-version-http-response-header/


推荐阅读