Loadrunner http JSON介面請求進行測試
阿新 • • 發佈:2019-01-25
Action()
{
//首先呼叫web_reg_find()這個註冊函式,我們介面的正常返回結果都是<Code>0</Code>
web_reg_find("Search=Body", //定義查詢範圍
"SaveCount=result", //定義查詢計數變數名稱
"Text=\"ret_code\":\"0000\"", //定義查詢內容
LAST);
web_custom_request("web_custom_request",
"URL=http://xxxx/xxxx/xxxx.json",
"Method=POST",
"Resource=0",
"RecContentType=application/json",
"Referer=",
"Mode=HTTP",
"EncType=application/json",
"Body={\"body\":{\"user_no\":\"123\",\"user_password\":\"123456\"}}",
LAST);
//剛才的web_reg_find()註冊函式派上用處,可以對結果進行統計
if (atoi(lr_eval_string("{result}")) > 0) //判斷如果<Code>0</Code>
//字串出現次數大於0
lr_output_message("request success"); //在日誌中輸出Log on successful
else
//如果出現次數小於等於
lr_error_message("request failed"); //在日誌中輸出Log on failed
return 0;
}
{
//首先呼叫web_reg_find()這個註冊函式,我們介面的正常返回結果都是<Code>0</Code>
web_reg_find("Search=Body", //定義查詢範圍
"SaveCount=result", //定義查詢計數變數名稱
"Text=\"ret_code\":\"0000\"", //定義查詢內容
LAST);
web_custom_request("web_custom_request",
"URL=http://xxxx/xxxx/xxxx.json",
"Method=POST",
"Resource=0",
"RecContentType=application/json",
"Referer=",
"Mode=HTTP",
"EncType=application/json",
"Body={\"body\":{\"user_no\":\"123\",\"user_password\":\"123456\"}}",
LAST);
//剛才的web_reg_find()註冊函式派上用處,可以對結果進行統計
if (atoi(lr_eval_string("{result}")) > 0) //判斷如果<Code>0</Code>
//字串出現次數大於0
lr_output_message("request success"); //在日誌中輸出Log on successful
else
//如果出現次數小於等於
lr_error_message("request failed"); //在日誌中輸出Log on failed
return 0;
}