我使用 java(和 http 客户端,或其他库)。我想向 Web 服务器发出 GET 请求(示例 http://MyDomain:8080/login.jsp)。
现在,我有 <html> .... </html>
和任何标题。
如何通过 java httpClient 查找目标 Web 服务器的任何信息(Tomcat 7.0.75、Linux 2016.09 v2.5.0、Java 8.0.233.3 ...)?
我的java代码是:
public class GetWebServerInfo {
public static void main(String[] args) throws ClientProtocolException,
IOException {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.mydomain...");
HttpResponse response = client.execute(request);
System.out.println(response);
Header[] headers = response.getAllHeaders();
for (Header header : headers) {
System.out.println("" + header);
}
}
}
我在控制台中的响应是:
Date: Sun, 12 Feb 2017 00:11:41 GMT
Server: Apache-Coyote/1.1
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Application-Context: application:prod:8080
Last-Modified: Sat, 11 Feb 2017 23:36:56 GMT
Accept-Ranges: bytes
Content-Type: text/html;charset=UTF-8
Content-Length: 3426
Keep-Alive: timeout=60, max=100
Connection: Keep-Alive
我没有Tomcat 8, ....
最佳答案
不同的服务器可能会或可能不会返回 header 来告诉您有关它们自己的信息。例如。
Server:Microsoft-IIS/8.5
X-Powered-By:ARR/3.0, ASP.NET
或
server:Oracle-Application-Server-11g
x-powered-by:Servlet/2.5 JSP/2.1
你不能要求信息,而且我认为很多服务器不会告诉你他们的操作系统。 “这关你什么事?”
我建议您打印出所有返回的 header 并向不同的服务器发出请求,看看您得到了什么,以及哪些对您有用。
How i can i display all the HTTP Headers when using the DefaultHTTPClient?
关于java - 如何通过 java httpClient 查找目标 Web 服务器的任何信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42182521/