1

In my Postman collection, I have a pre-request script that ensures I have a valid JWT token available for authentication. It looks similar to the following (I have removed the logic of checking expiration and only fetching a new token if needed):

function get_and_set_jwt() {
    let base_url = pm.environment.get("BASE_URL")
    pm.sendRequest({
        url: base_url + '/api/auth/',
        method: 'POST',
        header: {
            'content-type': 'application/json',
            'cookie': ''
            },
        body: {
            mode: 'raw',
            raw: JSON.stringify({ email: pm.environment.get("USER_EMAIL_ADDRESS"), password: pm.environment.get("USER_PASSWORD") })
        }
    }, function (err, res) {
        let jwt = res.json().token
        postman.setEnvironmentVariable("JWT", jwt)
    });
}


get_and_set_jwt();

I am attempting to set 'cookie': '' so that the request from this script will be made with no cookies. The backend I am working with sets a session cookie in addition to returning the JWT, but I want to force all future requests (when I need to renew the JWT) to not include that session information.

Unfortunately, if I check the Postman console, I see that the requests are still being sent with the cookie header, and the session cookie that was set by the earlier response. I have even tried overriding it by setting 'cookie': 'sessionid=""', but that just yields a request that includes two session ids in the cookie header (it looks like sessionid=""; sessionid=fasdflkjawew123sdf123;)

How can I send a request with pm.sendRequest with either a completely blank cookie header, or without the header at all?

0 Answers0