I am trying to return the response as string from my function using ResponseEntity but getting an error. I tried this:
@GetMapping(value="/getuserip")
public ResponseEntity<Object> getUserData(@RequestParam("username") String userName, HttpServletRequest request){
String ipAddr = (request.getHeader("X-FORWARDED-FOR"));
return new ResponseEntity<>(ipAddr, HttpStatus.SC_ACCEPTED);
}
When trying to return the String variable ipAddr I am getting the error. Do you know how to fix this?
The library for
httpstatus
was giving this error in my case. Fixed it by replacingorg.apache.http.HttpStatus
withorg.springframework.http.HttpStatus
.