Domanda

I want to know from which server a response comes.

With a HttpMethod I'm readig the HttpStatus, the Method-Name and other stuff. But how do I get to know the Response-Server?

Thanks for any help.

Edit:

boolean checkR(HttpMethod method){
    if (method.getStatusCode() == HttpStatus.SC_OK) {
        return true;
    } else {
        System.out.println("HTTP response was " + method.getStatusLine().toString());
        return false;
    } 
  }

I would like to return something like this: "HTTP response was " + method.getStatusLine().toString()) + "from Server " + ??? Server-name ??;

È stato utile?

Soluzione

Simple answer is that you cannot, since remote server address is not part of the HTTP response headers.

It is part of your request headers though with the field name HOST.

These are some of the headers fields in HTTP response:

ETag
Content-Length
Expires
Last-Modified
Connection
X-Powered-By
Server
Pragma
Cache-Control
Date
Vary
Keep-Alive
Content-Type
Accept-Ranges

See this link for complete list

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top