79259250

Date: 2024-12-06 20:11:06
Score: 1
Natty:
Report link

if you are looking to get ip address from servlet, inject HttpServletRequest and call in request.getRemoteAddr() method.

and if you're using reverse proxy request, check out this answer's comment https://stackoverflow.com/a/29910902/8733302

@RestController
public class HelloController {

    @Autowired
    private HttpServletRequest request;

    @PostMapping("/coolendpointTWO")
    public String withRequestBody(@RequestBody MyPojo myPojo) {

        System.out.println("received object" + myPojo);
        //handle myPojo with my business logic

        String ip = request.getRemoteAddr();
        return "good: " + ip;
    }

}
Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: ragav ravi