loadrunner傳k-v,用web_custom_request函數。android
init裏面執行登陸,根據返回獲取到tokenId,action中,執行登陸後的操做。web
詳細腳本以下: json
vuser_initapp
vuser_init() { //獲取response響應信息 //web_reg_save_param("response","LB=","RB=",LAST); //獲取tokenId值 web_reg_save_param("tokenId","Search=Body","LB=\"tokenId\":\"","RB=\"",LAST); //添加頭文件 //web_add_header("Content-Type","application/json;charset=utf-8"); web_add_header("imei","{userAccount}"); //web_add_header("Pragma","no-cache"); //web_add_header("appversion","2.1.1.2"); //web_add_header("systemversion","android:5.0.2"); web_custom_request("login", "URL=http://127.0.0.1:8081/login", "Method=POST", "Resource=0", "RecContentType=application/json", "Referer=", "Mode=HTTP", // O5WDjUwauLx3cACPSkczsElnGiD8n0RDGunFQDMecI96lmBzR5xc2VQhPV0NZbFdaik8tkZsq+kedFdomJ3A9fRklLkJT11IV45mZa9\/R45UslH\/hJqzPVShm\/9vVptgpwYbJZkhkcPx1LSeXJLPwg==|MTIzNDU2Nzg5MDk4NzY1NA==|9eU7qirx0+uJKqcedCzyBQ== "EncType=application/json", "Body={\"userAccount\":\"{userAccount}\",\"userPassword\":\"O5WDjUwauLx3cACPSkczsElnGiD8n0RDGunFQDMecI96lmBzR5xc2VQhPV0NZbFdaik8tkZsq+kedFdomJ3A9fRklLkJT11IV45mZa9\\/R45UslH\\/hJqzPVShm\\/9vVptgpwYbJZkhkcPx1LSeXJLPwg==|MTIzNDU2Nzg5MDk4NzY1NA==|9eU7qirx0+uJKqcedCzyBQ==\"}", LAST); //輸出code值 //lr_output_message("輸出code值:%s",lr_eval_string("{code}")); //輸出tokenId值 //lr_output_message("輸出tokenId值:%s",lr_eval_string("{tokenId}")); //對獲取response信息進行轉碼 //lr_convert_string_encoding(lr_eval_string("{response}"),LR_ENC_UTF8,"GBK","result"); //輸出response響應信息 //lr_output_message( "返回response響應信息:%s",lr_eval_string("{result}")); return 0; }
Actiondom
Action() { int res = 0; //int int_res = 0; //char * string_res = (char*)calloc(100,sizeof(char)); // 請求存儲空間 //設置檢查點 web_reg_find("Text=\"code\":\"00\"","SaveCount=c00",LAST); web_reg_find("Text=\"code\":\"8016\"","SaveCount=c8016",LAST); web_reg_find("Text=\"code\":\"8017\"","SaveCount=c8017",LAST); //web_reg_find("Text=\"code\":\"8001\"",LAST); //獲取response響應信息 //web_reg_save_param("response","LB=","RB=",LAST); lr_start_transaction("payPause"); web_custom_request("activityHandler", "URL=http://127.0.0.1:8081/payPause", "Method=POST", "Resource=0", "RecContentType=application/json", "Referer=", "Mode=HTTP", "EncType=application/json", "Body={\"tokenId\":\"{tokenId}\",\"cardNo\":\"62010101{userAccount}\"}", LAST); res = atoi(lr_eval_string("{c00}"))+atoi(lr_eval_string("{c8016}"))+atoi(lr_eval_string("{c8017}")); //下面四行是調試信息,int和string須要互轉 //sprintf(string_res,"%d",res); //int轉string //lr_output_message("string_res = %s",string_res); //int_res = atoi(string_res); //string轉int,其實這裏不須要轉了,由於res已是int,這裏只是再次體現string如何轉int //lr_output_message("int_res = %d",int_res); if (res > 0){ //lr_output_message("事務成功"); lr_end_transaction("payPause",LR_PASS); } else{ //lr_error_message("事務失敗"); lr_end_transaction("payPause",LR_FAIL); } //lr_convert_string_encoding(lr_eval_string("{response}"),LR_ENC_UTF8,"GBK","result"); //輸出response響應信息 //lr_output_message( "返回response響應信息:%s",lr_eval_string("{result}")); //lr_end_transaction("payPause", LR_AUTO); return 0; }
vuser_end函數
vuser_end() { return 0; }