Loadrunner - 使用 lr_save_string 连接

Loadrunner - concatenation using lr_save_string

是否可以使用 lr_save_string 连接?

sortoption、next 和 basket,bookIDs_array 都是正确分配的值。

代码

lr_save_string(lr_eval_string("sortoption={sortoption}&next={next}&basket={basket}"), "BodyString");
for (i=1; i<=lr_paramarr_len("BookIDS_array"); i++) {
lr_save_string(lr_paramarr_idx("BookIDS_array", i), "BookID");  
lr_save_string(lr_eval_string("{BodyString}&bookId%5B%5D%3D{BookID}"), "BodyString");
}
lr_output_message("Value: %s", lr_eval_string("{BodyString}"));

然而上面似乎只是将下面的分配给 BodyString

sortoption={sortoption}&next={next}&basket={篮子}

您可能需要考虑此其他线程作为 LoadRunner 中的串联示例

我查看了 XML link,它与我想做的非常相似,但如果有值,我需要更新一些 json。我对以下问题的处理方法:

    //Define the object to store.
        char ifPhoneThenAdd[100];
    ...
    ...
    ...
    //Capture the full part of the address information of the first entry including city, phone, etc. - In my scenario, all I need is the first one from the json response..
        web_reg_save_param_json("ParamName=AddressData","QueryString=$.Addresses","SelectAll=No",SEARCH_FILTERS,"Scope=Body",LAST);
    ...
    ...
    ...
    web_rest("......",
            "URL={App_URL}/details/{userID}",
            "Method=GET",
            "Snapshot=t999990.inf",
    LAST);
    ...
    ...
    ...
    //Some explanation of the json output:
    //A sample of the json output would look something like this (from the output tab):
    //Saving Parameter  "AddressData" =  [{"Id":"xxxxxxxxxxx","city":"Calgary","street":"123 Santas Workshop","postalCode":"H0H 0H0","country":"CA","region":"AB","email":"baba@oriley.com","phone":"403xxxxxxx"}]"
    //Without the phone, it would be:
    //[{"Id":"xxxxxxxxxxx","city":"Calgary","street":"123 Santas Workshop","postalCode":"H0H 0H0","country":"CA","region":"AB","email":"baba@oriley.com"}]"


    //This part changes the body in case there is a phone number and does not include phone number if there is none in the reply.
        sprintf(ifPhoneThenAdd,"");
        if (strstr(lr_eval_string("{AddressData}"), "\"phone\"") != NULL) 
        {
            lr_eval_json("Buffer={AddressData}", "JsonObject=json_obj", LAST);
            lr_json_get_values("JsonObject=json_obj", "ValueParam=AddressWithPhoneNumber", "QueryString=$..phone", "SelectAll=No", LAST);
            sprintf(ifPhoneThenAdd,"%s%s%s",",\r\n\"phoneNumber\":\"",lr_eval_string("{AddressWithPhoneNumber}"),"\"");
        }
        else
        {
            //Doesn't make the script fail, but will send an error message.
            lr_error_message("No phone number for ID: %s", lr_eval_string("{userID}"));
        }
        lr_save_string(ifPhoneThenAdd, "ifPhoneThenAddString");
    //If there is no phone, then the string ifPhoneThenAddString will be empty and nothing but the empty string will be added to the json output.
    //If there is a phone, then the body will get appended with the right json output with the phone number.
    ...
    ...
    ...
    web_rest("......",
            "URL={App_URL}/updateSomethingNeedingAddress/{userID}",
            "Method=POST",
            "EncType=raw",
            "Snapshot=t999991.inf",
            "Body={\r\n"
            "\"Id\":\"{userID}\",\r\n"
            "\"firstName\":\"{userFirstname}\",\r\n"
            "\"lastName\":\"{userLastname}\",\r\n"
            "\"streetName\":\"{userStreetName}\",\r\n"
            "\"city\":\"{userCity}\",\r\n"
            "\"province\":\"{userProvince}\",\r\n"
    //This part will add the phone part if there is one after the postalCode.  If no phone, the postalCode will be the last part of the json.
            "\"postalCode\":\"{userPostalCode}\"{ifPhoneThenAddString}\r\n"
            "}",
            HEADERS,
            "Name=Content-Type", "Value=application/json", ENDHEADER,
            LAST);
    ...
    ...
    ...
        return 0;