0

I will be grateful for your help :)

I have a frontend on port 4200 and backend on 8080, and after authentication i redirect it from 8080 to 8080 (another endpoint) to save a new user and after that, I need to redirect to localhost:4200...

HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.setLocation(Paths.get(url + "/home").toUri());
        return ResponseEntity.ok()
                .headers(responseHeaders)
                .body(cookie);

But I only get a response There was an unexpected error (type=Internal Server Error, status=500). Illegal char <:> at index 4: http://localhost:4200/home

BFST
  • 72
  • 6

1 Answers1

1

Try this:

HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setLocation(URI.create(url + "/home"));
return ResponseEntity.status(HttpStatus.FOUND)
                .headers(responseHeaders)
                .body(cookie);

It seems that the error occurs at Paths.get. If you want to create a java.net.URI object, use URI#create instead.

I think you make a mistake in setting HTTP status code. If you want to make a redirect response, you have to use 3xx status code instead of 200(ResponseEntity#ok).

Related Questions

Spring MVC @RestController and redirect
Redirect to dynamic URL in Spring MVC

Tomoki Sato
  • 578
  • 4
  • 11