I´m sending a request which returns a 30x and Postman automatically follows the redirect, which is fine.
How can I programmatically “see” the URL I´m redirected to, eg in the test tab?
This has been raised as an issue before (https://github.com/postmanlabs/postman-app-support/issues/319), but as I understand the latest comment, the given solution is not working anymore?
Anyhow, I want to get that value in the test tab, not in some Addon.
Using the pm.response.headers object in the test tab of Postman,
you may programmatically get the URL you’re being redirected to.
You can specifically look at the Location header, which typically includes the URL to which you were forwarded following a 30x answer.
Ex:
// Check if the response has a redirect status code (30x)
if (pm.response.code >= 300 && pm.response.code < 400) {
// Get the 'Location' header from the response headers
var redirectUrl = pm.response.headers.get('Location');
console.log('Redirected URL: ', redirectUrl);
}
On this pm.response.headers.get(‘Location’) method retrieves the value of the Location header from the response headers, which should contain the URL you were final redirected to.