Reputation: 77
So I am trying to do a POST request with body to an endpoint that returns a redirect to another URL with the status code of 302. Can I make this POST request from backend and retrieve the redirect URL as a String?
Thank you.
The endpoint I am calling looks like this and I need that redirect URL:
@PostMapping(value = "/something")
public String doSomething(@RequestBody @NotNull final MultiValueMap<String, String> someMap) {
doSomethinWithData();
return "redirect:" + someUrl + "/abcd/" + "123457";
}
}
Upvotes: 0
Views: 460
Reputation: 868
You can submit the post request and then check for response code and return the Location Header.
if (myConnection.getResponseCode() == 302) {
String myRedirectUrl = myConnection.getHeaderField("Location");
return myRedirectUrl ;
}
Upvotes: 1