如何从Apache HTTP客户端响应中删除服务器/软件信息

时间:2019-04-11 12:53:41

标签: java xampp apache-httpclient-4.x apache-httpcomponents apache-httpclient-5.x

我写了下面的示例程序来检查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

1 个答案:

答案 0 :(得分:0)

下面提到的服务器详细信息由服务器(例如您的本地主机)发送。

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/