1. 程式人生 > >LR指令碼示例之URL請求(post、get)

LR指令碼示例之URL請求(post、get)

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;
}