I want to store the URL/ip that I received the request from.
For example I am (server) receives the request from ip address 176.15.14.3.
I want to get that ip address 176.15.14.3
Can I do that with Spring.
I want to store the URL/ip that I received the request from.
For example I am (server) receives the request from ip address 176.15.14.3.
I want to get that ip address 176.15.14.3
Can I do that with Spring.
X-Forwarded-For value gives you the IP address of client. You can get the IP like below in spring.
String remoteAddress = request.getHeader("X-Forwarded-For");//request--HTTPServletRequest Object
if (remoteAddress == null) {
remoteAddress = request.getRemoteAddr();
}
Assuming you have access to the HttpServletRequest
Object, just call response.getRemoteAddr() which returns the remote host's ip represented as a string.
See here