Site icon Hip-Hop Website Design and Development

Get returned URL from wp_remote_post if response code is 302

I’m sending a POST request to an API:

$response = wp_remote_post( "www.example.com/redirect_me", $payload );

The API endpoint returns a 302 redirect to a different URL: www.you-got-redirected.com.

How can I access www.you-got-redirected.com as a variable in PHP? I’m aware of wp_remote_retrieve_body but that’s for the contents, not the URL.

I don’t want to change the behavior of the API, and the documentation for wp_remote_post() says nothing about how to access the contents of the response.

EDIT: tried this but it always returns empty string

$redirect_to = wp_remote_retrieve_header( $reponse, 'Location' );