一下这段代码,包含了手动编写脚本、添加检查点、手动关联、添加cookie和其他一些常用的小函数,贴出来偶尔可以学习一下
char * ip="10.1.60.23:8001";
lr_save_string(ip,"lrip");
//web_set_max_html_param_len("99999");
//获取登录的验证码cookie
web_reg_save_param("verify_Cookie",
"LB=Set-Cookie: ",
"RB=; Path=/; ",
"Search=Headers",
"ORD=2",
LAST);
lr_start_transaction("登录");
web_url("isLogin",
"URL=http://{lrip}/mapi/product/isLogin.htm",
"TargetFrame=",
"Resource=0",
"Referer=",
LAST);
//获取登录结果
web_reg_save_param("login_Response",
"LB=",
"RB=",
"Search=Body",
LAST);
//检查登录结果
web_reg_find("SaveCount=login_result",
"Text=\"code\":0,",
LAST);
//获取登录成功的cookie
web_reg_save_param("login_Cookie",
"LB=Set-Cookie: ",
"RB=; Expires=",
"Search=Headers",
"ORD=4",
LAST);
//登录时,带上验证码的cookie
web_add_header("Cookie",lr_eval_string("{verify_Cookie}"));
web_submit_data("login",
"Action=http://{lrip}/user/login.htm",
"Method=POST",
"TargetFrame=",
"Referer=",
ITEMDATA,
"Name=accountName", "Value={loginname}", ENDITEM,
"Name=password", "Value=e10adc3949ba59abbe56e057f20f883e", ENDITEM,
LAST);
if(atoi(lr_eval_string("{login_result}"))>0)//加强型检查点
{
lr_end_transaction("登录", LR_PASS);
}
else
{
lr_end_transaction("登录", LR_FAIL);
lr_convert_string_encoding(lr_eval_string("{login_Response}"),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE, "login_Response_new");//字符类型转换
lr_error_message("登录返回错误:%s,失败的用户:%s",lr_eval_string("{login_Response_new}"),lr_eval_string("{accountName}"));
}