以编程方式删除邮递员中的cookie [英] Deleting cookies in postman programmatically

查看:75
本文介绍了以编程方式删除邮递员中的cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Newman和本地Windows Postman应用程序来测试REST API。它存储请求之间的会话cookie,使我可以访问需要授权的信息而无需提供正确的授权。我希望能够在请求前脚本部分中删除Cookie。这可能吗?我知道如何通过阅读等问题来使用GUI删除Cookie邮递员中的cookie?和邮递员的官方文档,但这对我没有帮助。

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.

推荐答案

Postman v7.6.0已添加对程序化cookie访问的支持。因此,如果要在请求前脚本中删除Cookie,则可以执行以下操作:

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:

删除单个Cookie

const jar = pm.cookies.jar();

jar.unset(pm.request.url, 'cookie name', function (error) {
  // handle error
});

删除所有cookie

const jar = pm.cookies.jar();

jar.clear(pm.request.url, function (error) {
  // handle error
});




您可以在此处找到API的详细概述:
https://学习。 getpostman.com/docs/postman/sending-api-requests/cookies/#programmatic-accees-of-cookies

这篇关于以编程方式删除邮递员中的cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆