[英]Loadrunner, how to get cookie value?
After authorizing in my website, it creates special value in Cookies:在我的网站上授权后,它在 Cookies 中创造了特殊的价值:
Cookies: session=bb415f62-eb9e-42fa-aedf-ca1887548216
The value of this cookie is required for other API calls on my website.我网站上的其他 API 调用需要此 cookie 的值。 My autogenerated script created this:我的自动生成的脚本创建了这个:
web_add_header("token",
"bb415f62-eb9e-42fa-aedf-ca1887548216");
However, there is a problem.但是,有一个问题。 Value of Cookie session constantly changes after each authorization. Cookie session 的值在每次授权后不断变化。 This web_add_header
has constant value, which is expired.此web_add_header
具有常量值,已过期。
Is it possible to get value from Cookie and set it to header in loadrunner?是否可以从 Cookie 中获取价值并在 loadrunner 中将其设置为 header?
Please check the following example for Web HTTP protocol:请检查以下示例以了解 Web HTTP 协议:
You will need something like this to extract cookie value:您将需要这样的东西来提取 cookie 值:
// Set-Cookie: session=bb415f62-eb9e-42fa-aedf-ca1887548216; path=/
web_reg_save_param_ex(
"ParamName=session",
"LB=session=",
"RB=;",
"Ordinal=all",
"Notfound=warning",
SEARCH_FILTERS,
"Scope=Cookies",
LAST);
then use it like this:然后像这样使用它:
web_add_header("token", "{session}");
Here is a runnable example:这是一个可运行的示例:
//Extract the uuid and save it under "session" parameter
web_reg_save_param_ex(
"ParamName=session",
"LB=\"uuid\": \"",
"RB=\"",
"Ordinal=all",
"Notfound=warning",
SEARCH_FILTERS,
"Scope=Body",
LAST);
web_url("get data",
"URL=http://httpbin.org/uuid",
"Snapshot=t1.inf",
LAST);
if (atoi(lr_eval_string("{session_count}"))>0) lr_save_string(lr_eval_string("{session_1}"),"token");
web_add_header("token", "{token}");
web_reg_save_param_ex(
"ParamName=session",
"LB=\"uuid\": \"",
"RB=\"",
"Ordinal=all",
"Notfound=warning",
SEARCH_FILTERS,
"Scope=Body",
LAST);
web_url("get data_2",
"URL=http://httpbin.org/uuid",
"Snapshot=t2.inf",
LAST);
//If there is a new session, overwrite the token parameter
if (atoi(lr_eval_string("{session_count}"))>0) lr_save_string(lr_eval_string("{session_1}"),"token");
web_add_header("token", "{token}");
web_reg_save_param_ex(
"ParamName=session",
"LB=\"uuid\": \"",
"RB=\"",
"Ordinal=all",
"Notfound=warning",
SEARCH_FILTERS,
"Scope=Body",
LAST);
web_url("get data_3",
"URL=http://httpbin.org/uuid",
"Snapshot=t3.inf",
LAST);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.