如何在Postman中存储和重用cookie?

编程入门 行业动态 更新时间:2024-10-25 22:34:54
本文介绍了如何在Postman中存储和重用cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用邮递员来测试和使用API​​.

I'm using Postman to test and play with an API.

对于登录URL,API要求发送一个以 username 和 password 作为字段的POST请求.执行此操作后,我收到登录消息后收到 200 响应.

For the login url, the API requires sending a POST request with username and password as fields. I do this, and I get a 200 response with the message that I am logged in.

然后我尝试另一个请求以获取用户数据.但是,我得到的响应是我尚未登录.

I then try another request to get user data. However, I get a response that I am not logged in.

我意识到这个问题很可能是因为我登录时发送给我的cookie不包含在下一个邮递员请求中.

I realized this problem is most likely because the cookie that is sent to me when I log in is not included in the next Postman request.

所以我的问题是,如何保存和包括cookie以用于将来的请求?

So my question is, how do I save and include cookies for future requests?

推荐答案

将要使用的cookie值存储在全局变量中.在登录请求的 Tests 标签中,写

Store the cookie value you want to use in a global variable.In Tests tab of login request, write

postman.setGlobalVariable('key', postman.getResponseCookie("cookieName").value);

将 Headers 选项卡中的值作为cookie传递到获取用户请求中:

Pass along with the value in the Headers tab as a cookie in get user request:

Cookie | cookieName={{key}}

更多推荐

如何在Postman中存储和重用cookie?

本文发布于:2023-10-29 09:41:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539366.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Postman   cookie

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!