如何在Postman中存储和重用cookie? [英] How to store and reuse cookies in Postman?

查看:56
本文介绍了如何在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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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