Deleting cookies in postman programmatically

妖精的绣舞 提交于 2020-06-11 17:08:47

问题


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



来源:https://stackoverflow.com/questions/45287224/deleting-cookies-in-postman-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!