1

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?

stan3098
  • 31
  • 5
  • Found the issue. It was giving the error due to me importing the wrong library for httpstatus. I should have imported org.springframework.http.HttpStatus but I imported org.apache.http.HttpStatus thus resulting in the error. Thanks – stan3098 Mar 19 '22 at 10:19

1 Answers1

2

The library for httpstatus was giving this error in my case. Fixed it by replacing org.apache.http.HttpStatus with org.springframework.http.HttpStatus.

Lrrr
  • 4,755
  • 5
  • 41
  • 63
stan3098
  • 31
  • 5