request.getRemoteHost() vs request.getHeader("HOST")

Viewed 650
2 Answers
  1. request.getRemoteHost() : Returns the fully qualified name of the client that sent the request.

    So, If you access it via localhost you would get something like : 0:0:0:0:0:0:0:1. If you access it via some other machine, it will return you the IP address of that machine.

  2. request.getHeader("HOST") : Returns the value of the "Host" header in the request.

    So, If you are hitting an application url : https://www.test.com, then request.getHeader("Host") would return you www.test.com

The short answer is: NO

The explanation is already there in the links you have provided.

Given below is the one for request.getHeader("HOST"):

The Host request header specifies the host and port number of the server to which the request is being sent.

And the one below is about request.getRemoteHost():

Returns the fully qualified name of the client or the last proxy that sent the request. If the engine cannot or chooses not to resolve the hostname (to improve performance), this method returns the dotted-string form of the IP address.

Related