Access Request Headers after hitting the request

My question:

Is it possible to access request-header after the request is hit?

var Cookie = null
pm.sendRequest("", function (err, response, options) {
    Cookie = options.cookies.members[0].value;
pm.globals.set("Cookie", Cookie);
pm.environment.set("Cookie", Cookie);
pm.request.headers.add({key: "Cookie", value: Cookie});

So basically I want to capture the auto-generated(auto-injected) Request-Header Cookie from the pre-request script and use it in the actual request

I’ve already tried:

  • options.cookies.member
  • request.headers
  • pm.cookies

Hi @maintenance-enginee2



Example req;


But that’s the catch, the Cookie Header in the actual Example Request is Empty.
So let me try to explain once again :

Step - 1 : Hit a Dummy request in Pre-request script(this will generate and USE a Cookie in the Request header)
Step - 2 : Use the Cookie from the Pre-request script Dummy Request header in the actual Hit of a Request

So according to your screenshot, Exmaple Req screenshot is not going to have any Cookie value, rather it has to be embedded with the actual Cookie which should be extracted from the Pre-request script.

Ahh, I see, yes, slightly different to what I thought you meant.

There is some really good info on this topic here;

Hopefully, this would help you!

Not really, we still have the same problem. But thanks much for the reference.
@baljindernohra / @allen.helton - were you guys able to solve this finally?
Really need some help here

Could you not submit the call as an actual call, rather than as a pre-req script? would be dead easy to strip out the value that way… is there a reason it has to be in the pre-req?

Hi @w4dd325 James - thanks for your response.
But I can’t submit it directly because my intention is to skip a redirect call.
So for OAuth2/OIDC, when we hit a request, it goes for a redirection to the Auth Server and then comes back to hit the actual request, I want this kind of behavior for my actual request.

Steps that take place in my app/Google-Chrome :

  1. Hit the URL on Chrome or App
  2. Chrome/App gets a 302 redirect for the OIDC server proxy
  3. Chrome/App gets the token from the OIDC server
  4. Uses that token to hit the actual URL once again

Let me tell you the steps I want to achieve via POSTMAN :

  1. Hit the dummy URL, acquire the Tokens from the Request header
  2. Use this token to hit the actual Request directly

I am not sure how to achieve redirection in POSTMAN