[英]Loadrunner, how to get cookie value?
在我的網站上授權后,它在 Cookies 中創造了特殊的價值:
Cookies: session=bb415f62-eb9e-42fa-aedf-ca1887548216
我網站上的其他 API 調用需要此 cookie 的值。 我的自動生成的腳本創建了這個:
web_add_header("token",
"bb415f62-eb9e-42fa-aedf-ca1887548216");
但是,有一個問題。 Cookie session 的值在每次授權后不斷變化。 此web_add_header
具有常量值,已過期。
是否可以從 Cookie 中獲取價值並在 loadrunner 中將其設置為 header?
請檢查以下示例以了解 Web HTTP 協議:
您將需要這樣的東西來提取 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);
然后像這樣使用它:
web_add_header("token", "{session}");
這是一個可運行的示例:
//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.