使用 Postman 获取和存储 cookie 的值Postman、cookie

2023-09-08 08:51:53 作者:入魔了

我需要获取 cookie 的值,该值仅在我在 postman 中发送请求时创建.

我已经尝试了一切,但我不知道如何实现这一点.我还需要存储该值以用于我的项目的进一步请求.

获取cookies的方法及使用postman进行接口关联

cookie 名称:JSESSIONID值:09840****************00C44

解决方案

你可以使用 pm.environment.set('my_cookie', pm.cookies.get('JSESSIONID')) 函数在 Tests 选项卡中,并将其存储为 environment 变量.

然后可以通过使用 {{my_cookie}} 语法在下一个/任何请求正文或请求标头等中使用它.

可以在此处找到一个非常相似的问题..p>

I need to get the value of a cookie, that is only created when I send a request in postman.

I have tried everything but I don't know how to achieve this. I also need to store that value to use in further requests for my project.

cookie name: JSESSIONID value:09840****************00C44

解决方案

You could use the pm.environment.set('my_cookie', pm.cookies.get('JSESSIONID')) function in the Tests tab and store it as an environment variable.

This can then be used in the next/any Request Body or Request Header etc by referencing it using the {{my_cookie}} syntax.

A very similar issue can be found here.