Disable auto redirct in pre request script

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 :wave: Welcome to the Postman Community :tada:

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,

payload: imsomething

postman console:
GET:www.somedomain.com/v1/fetch 302 ( redirect → somedomain.com )
GET: somedomain.com XXX ( any http request )



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?

pm.sendRequest(YOUR_URL, (err, res) => {
    if (res.code === 302) {
        throw new Error('302 redirection is terminated')