1. 程式人生 > >LR腳本示例之URL請求(post、get)

LR腳本示例之URL請求(post、get)

code start count last item sta val content orm

Action()
{
//application/x-www-form-urlencoded
//application/json
//web_add_auto_header("Content-Type","application/x-www-form-urlencoded");設置請求頭信息

//1、停頓2秒
lr_think_time(2);

//2、設置檢查點
web_reg_find("SaveCount=count",
"Text=\"error_code\":0",
LAST);

//3、開始get請求
lr_start_transaction("get請求");

//4、提交get請求
web_url("get請求",
"URL=http://v.juhe.cn/laohuangli/d?date=2016-11-18&key=e711bc6362b3179f5a28de7fd3ee4ace",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t7.inf",
"Mode=HTML",
LAST);

//5、判斷事物是否成功
if(atoi(lr_eval_string("{count}")) > 0)
{
//結束get請求
lr_end_transaction("get請求", LR_PASS);
lr_output_message("get請求=%s", lr_eval_string("{count}"));
lr_output_message("get請求成功");

}
else
{
//結束get請求
lr_end_transaction("get請求", LR_FAIL);
lr_output_message("get請求失敗");
}

//1、停頓2秒
lr_think_time(2);

//2、獲取檢查post請求的關聯
web_reg_save_param("errorCode",
"LB=\"error_code\":",
"RB=\}",
LAST);

//3、設置html支持的字符長度為1024
web_set_max_html_param_len("1024");

//4、開始post請求
lr_start_transaction("post請求");

//5、提交post請求
web_submit_data("post請求",
"Action=http://v.juhe.cn/laohuangli/d",
"Method=POST",
"TargetFrame=",
"RecContentType=application/json",
"Referer=",
"Snapshot=t12.inf",
"Mode=HTML",
ITEMDATA,
"Name=date", "Value=2016-11-18", ENDITEM,
"Name=key", "Value=e711bc6362b3179f5a28de7fd3ee4ace", ENDITEM,
"Name=uri", "Value=", ENDITEM,
LAST);


//6、判斷post請求事物是否成功
if(atoi(lr_eval_string("{errorCode}"))==0)
{
//結束post請求
lr_end_transaction("post請求", LR_PASS);
lr_output_message("post請求成功=%s", lr_eval_string("{errorCode}"));
lr_output_message("post請求成功");

}
else
{
//結束post請求
lr_end_transaction("post請求", LR_FAIL);
lr_output_message("post請求失敗");
}


return 0;
}

LR腳本示例之URL請求(post、get)