2019-10-17 loadrunner 接口压测脚本

Action()

{

char *url_request = "http://xxx.xxx.xxx.xxx/ktsapi/api/InterfaceHubs";

    // 定义请求返回码变量

    int HttpRetCode;

    lr_save_string(url_request,"URL_REQUEST");

web_add_header("Content-Type",

  "application/json;charset=UTF-8");

web_add_header("RequestTime",

  "1565234210");

web_add_header("UserName",

  "test");

web_add_header("Signature",

  "TD6X1VN5PVQA2nAO11WKPV6IhM8=");

web_add_header("Module",

  "MakeLottery");

web_add_header("Nonce",

  "NT19meL2RzsAIBcrajXfQoxl8");

    // 返回值参数化处理,取所有响应数据

    web_reg_save_param_ex("ParamName=getInitData",

                          "LB=",

                          "RB=",

                          LAST);

/*

web_reg_save_param("ParamStatus=getInitStatus",

  "LB={\"IsSucceed\":",

  "RB=,\"ErrorCode",

  LAST);*/

lr_start_transaction("InterfaceHubs");

    web_custom_request("initData",

                      "URL={URL_REQUEST}",

                      "Method=POST",

                      "Referer=",

                      "EncType=application/json",

                      "RecContentType=application/json",

                      "Body={\"BrandId\":\"Hydron\",\"CustomerId\":\"{customerid1}\",\"CampaignCode\":\"Campaigncode1015\",\"CustomerTag\":\"{tag}\",\"Channel\":\"Line\",\"IsConsumePoint\":true,\"TagCode\":\"{tag}\"}",

                      "Mode=HTTP",

                        LAST);

HttpRetCode = web_get_int_property(HTTP_INFO_RETURN_CODE);

if (HttpRetCode == 200){

lr_log_message(">>> success <<<");

lr_end_transaction("InterfaceHubs", LR_PASS);

}else {

lr_error_message(">>> fail <<<");

lr_end_transaction("InterfaceHubs", LR_FAIL);

}

// 对返回值转码

lr_convert_string_encoding(lr_eval_string("{getInitData}"),

    LR_ENC_UTF8,

  "GB2312",

  "getInitDataEnc");

lr_output_message(lr_eval_string("{getInitDataEnc}"));

return 0;

}

        /*if(strcmp(lr_eval_string("{ParamStatus}"), "true") == 0){

lr_output_message(lr_eval_string("{ParamStatus}"));

}*/

你可能感兴趣的:(2019-10-17 loadrunner 接口压测脚本)