4

Is there a way of defining a httpOnly cookie in Postman and send it to the client is requesting it?

Thanks in advance for your help.

Regards

ESRISM
  • 101
  • 1
  • 10

1 Answers1

0

In version 7.3.5-canary04 onwards in the Canary build of Postman, you can programmatically set cookies from a pre-request script.

You would need to add the Domain to the whitelist before sending the request, once that's been added, you could use any of these methods to add the cookie to the request.

const jar = pm.cookies.jar();

// using cookie name and value
jar.set('http://example.com', 'token', '123456', function (error, cookie) {
  // error - <Error>
  // cookie - <PostmanCookie>
  // PostmanCookie: https://www.postmanlabs.com/postman-collection/Cookie.html
});

// using set-cookie string
jar.set('http://example.com', 'token=123456; Path=/; HttpOnly;', function (error, cookie) {
  // error - <Error>
  // cookie - <PostmanCookie>
});

// using PostmanCookie or its compatible object
jar.set(pm.request.url, { name: 'token', value: '123456', httpOnly: true }, function (error, cookie) {
  // error - <Error>
  // cookie - <PostmanCookie>
});

Postman Cookies

More information can be found here:

https://github.com/postmanlabs/postman-app-support/issues/3312#issuecomment-516965288

Danny Dainton
  • 23,069
  • 6
  • 67
  • 80