1

Iv'e been using this guide: https://spring.io/guides/gs/rest-service to create a RESTFul web service, my issue I am having is that I do not know how to get information such as the clients IP address, is this possible with this API?

Thanks,

1

1 Answer 1

1

In your Spring Rest Controller you can add HttpServletRequest to get client info.

Example

@GetMapping("/dummyurl")
public Boolean syncWithServNow(HttpServletRequest httpReq, @RequestParam("username") String username) {
    System.out.println(httpReq.getRemoteAddr());  // Line 1
}

In most cases it will work. In case like url is accessed by web server over a proxy server or has a load balancer this will do.

httpReq.getHeader("X-FORWARDED-FOR");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.