My question:
I making an HTTP call in pre-request-script, which redirects (302) to another URL.
Postman allows disabling redirection for request fired from UI
I want to stop redirection in pre-request-script or get the request/ response object , i dont see any documentaion for pm.sendRequest , it has only err, response, cookie in callback
pm.sendRequest(options, (err, res, cookie) => {});
I’ve already tried:
I’ve hit the wall , i any options to try
Hey @vivekanandansakthive Welcome to the Postman Community
I would like to test how the redirection works in pre-request script on my own, so if you don’t mind would you please share an example HTTP URL that you are using?
I am looking forward to hearing back from you!
@taehoshino, HTTP URL I’m trying is something specific to an enterprise system that i cannot share in a forum.
This is how the postman behavior,
sendRequest(‘GET:www.somedomain.com/v1/fetch’)
response:
{
payload: imsomething
}
postman console:
GET:www.somedomain.com/v1/fetch 302 ( redirect → somedomain.com )
GET: somedomain.com XXX ( any http request )
Expectation:
sendRequest(‘GET:www.somedomain.com/v1/fetch’)
postman console:
GET:www.somedomain.com/v1/fetch 302 ( redirect → somedomain.com )
→ terminate and invoke callback
Hey @vivekanandansakthive!
I have not been able to test it on my end, but can you include if
clause to check status code?
e.g.
pm.sendRequest(YOUR_URL, (err, res) => {
if (res.code === 302) {
throw new Error('302 redirection is terminated')
}
})
Hi @taehoshino
It doesn’t work, even if I disable automatic redirects in Settings. res.code == 200 as it is being redirected before this handler executed