Stéphane GRILLON
Stéphane GRILLON

Reputation: 11862

How find any informations of target Web server by java httpClient?

I use java (and http client, or other lib). I Want doing a GET request to a web server (sample http://MyDomain:8080/login.jsp).

Now, I have <html> .... </html> and any headers.

How find any informations (Tomcat 7.0.75, Linux 2016.09 v2.5.0, Java 8.0.233.3...) of target Web server by java httpClient?

My java code is:

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);
        }
    }
}

My response in console is:

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

I do not have Tomcat 8, ....

Upvotes: 0

Views: 151

Answers (1)

slipperyseal
slipperyseal

Reputation: 2778

Different servers may or may not return headers telling you about themselves. eg.

Server:Microsoft-IIS/8.5
X-Powered-By:ARR/3.0, ASP.NET

or

server:Oracle-Application-Server-11g
x-powered-by:Servlet/2.5 JSP/2.1

You can't demand information and I don't think many servers will be telling you about their operating system. "Why is that any of your business?"

I recommend you print out all the returned headers and make requests to different servers and see what you get, and what can be of use to you.

How i can i display all the HTTP Headers when using the DefaultHTTPClient?

Upvotes: 1

Related Questions