java - 如何从 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
解决方案
下面提到的服务器详细信息由服务器发送,即在您的情况下为 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/
推荐阅读
- batch-file - 在主批处理文件中执行多个批处理文件的问题
- css - 如何在不使其透明的情况下模拟元素的不透明度效果?
- angular - 单击此处如何仅显示一个组件?
- reference - 如何将事件更改从子组件传递给父组件
- c - 如何将数组保存在 .txt (C)
- c# - MySQL 应用程序连接
- jitterbit - 使用 Jitterbit 从 Salesforce 下载多个附件
- css - SVG 笔画、CSS 动画:并非所有笔画都朝同一个方向移动
- android - ARCore - 让相机面向世界的角度向前(-Z 轴)
- java - How to fix a "money sorter" java program