jmeter中添加cookie可以通过配置HTTP Cookie Manager ,也可以通过HTTP Header Manager,因为cookie是放在头文件里发送的。

实例:博客园点击添加新随笔 https://i.cnblogs.com/EditPosts.aspx?opt=1
如果未登录,跳转登录页; 如果已登录,会打开添加随笔页面。请求一样,区别只在于是否添加cookie。
第一步 添加thread group 》 添加http request 和 View Results Tree 》运行

结果树显示跳转登录页:

第二步方式一 添加HTTP Cookie Manager,写入cookie。
cookie获取方式:登录博客园 》chrome浏览器按F12打开调试 》 点击网页上的新随笔 》调试窗口Application 》storage 》cookies 》https://i.cnblogs.com


运行,查看结果树中的请求和响应。请求确实带入cookie信息,响应进入添加随笔页面。


方式二 添加HTTP Header Manager。将头信息里的cookie信息拷贝粘贴进去。
cookie获取方式:登录博客园 》chrome浏览器按F12打开调试 》 点击新随笔 》调试窗口Network 》headers 》request headers 》cookie


运行,查看结果树中的请求和响应:


HTTP Cookie Manager特别之处在于会自动保留前面请求的response cookie。比如前一个请求登录返回cookie,然后加一个空白的HTTP Cookie Manager自动获取cookie。
