0

After authorizing in my website, it creates special value in Cookies:

Cookies: session=bb415f62-eb9e-42fa-aedf-ca1887548216

The value of this cookie is required for other API calls on my website. 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. This web_add_header has constant value, which is expired.

Is it possible to get value from Cookie and set it to header in loadrunner?

Mr.D
  • 7,353
  • 13
  • 60
  • 119

1 Answers1

0

Please check the following example for Web HTTP protocol:

You will need something like this to extract cookie value:

//  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);   
Buzzy
  • 2,905
  • 3
  • 22
  • 31
  • When I use your code, I get this warning message: `No match found for requested parameter session`. Do we need some kind of parameters that specifies domain cookies? – Mr.D Nov 25 '19 at 06:25
  • This is just an example. If you want me to look at a particular URL that I can access I can add specific code for that URL. – Buzzy Nov 25 '19 at 09:44
  • I have just sent an email – Mr.D Nov 25 '19 at 10:05