我在下面写了示例程序来检查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
下面提到的服务器详细信息由服务器发送,即您的案例中的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/