I'm using Newman and the native Windows Postman app to test a REST API. It stores the session cookie between requests, allowing me to access information that requires authorization without providing correct authorization. I would like to be able to delete the cookie within the pre-request script section. Is this possible? I know how to delete cookies using the GUI through reading questions such as How to delete session cookie in Postman? and the official postman documentation but that doesn't help me deal with this issue.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Postman v7.6.0 has added support for programmatic cookie access. Hence, if you want to delete a cookie in the pre-request script, you can do the following:
Remove a single cookie
const jar = pm.cookies.jar();
jar.unset(pm.request.url, 'cookie name', function (error) {
// handle error
});
Remove all cookies
const jar = pm.cookies.jar();
jar.clear(pm.request.url, function (error) {
// handle error
});
You can find a detailed overview of the API here: https://learning.getpostman.com/docs/postman/sending-api-requests/cookies/#programmatic-accees-of-cookies
回答2:
This is not currently possible with Postman, it's an open feature request at the moment:
https://github.com/postmanlabs/postman-app-support/issues/3312#issuecomment-413750185