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

查看:32
本文介绍了Postman中如何存储和重复使用cookies?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Postman 来测试和使用 API.

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

对于登录 url,API 需要发送一个带有 usernamepassword 作为字段的 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 没有包含在下一个 Postman 请求中.

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中如何存储和重复使用cookies?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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