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

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

问题描述

我正在使用 Newman 和本机 Windows Postman 应用程序来测试 REST API.它在请求之间存储会话 cookie,允许我在不提供正确授权的情况下访问需要授权的信息.我希望能够在预请求脚本部分中删除 cookie.这可能吗?我知道如何通过阅读诸如 如何删除会话之类的问题使用 GUI 删除 cookiePostman 中的 cookie? 和官方邮递员文档,但这并不能帮助我处理这个问题.

解决方案

Postman v7.6.0 增加了对程序化 cookie 访问的支持.因此,如果您想删除预请求脚本中的 cookie,您可以执行以下操作:

删除单个 cookie

const jar = pm.cookies.jar();jar.unset(pm.request.url, 'cookie name', function (error) {//处理错误});

删除所有 cookie

const jar = pm.cookies.jar();jar.clear(pm.request.url,函数(错误){//处理错误});

<块引用>

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

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 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

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

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