get请求代码:
Action()
{
//检查点
/*
web_reg_find("Search=Body",
"SaveCount=result",
"Text=true",
LAST);
*/
//关联
web_reg_save_param("result",
"LB=result\":",
"RB=}",
"Ord=1",
LAST);
//事务开始
lr_start_transaction("get");
//打开get请求接口
web_url("GetMethod_getSkuInfo.action",
"URL=http://127.0.0.1:8080/PerfTeach/GetMethod_getSkuInfo.action?skuId=123&opt=lee",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
EXTRARES,
"Url=../favicon.ico", "Referer=", ENDITEM,
LAST);
/*和检查点相匹配,检查的文本内容出现的 次数 大于0(即为存在要进行检查的文本)
if (atoi(lr_eval_string("{result}")) > 0){
lr_end_transaction("get", LR_PASS);
}else{
lr_end_transaction("get", LR_FAIL);
}
*/
if( strcmp(lr_eval_string("{result}"), "true" ) ) //关联和strcmp
{
lr_end_transaction("get", LR_PASS);
}else{
lr_end_transaction("get", LR_FAIL);
}
return 0;
}
post请求代码:
Action()
{
//关联
web_reg_save_param("resultq",
"LB=msg\":\"",
"RB=\"",
"Ord=1",
LAST);
//事务开始
lr_start_transaction("post");
//自定义请求。这个函数web_custom_request可以自定义任何类型的请求
web_custom_request("post", "Method=POST",
"URL=http://127.0.0.1:8080/PerfTeach/PostMethod_reg.action",
"Body=data={\"username\":\"jack\",\"password\":\"123\",\"email\":\"[email protected]\",\"phone\":110}",//post body需要 逗号 分割
"TargetFrame=",
LAST );
//转码前打印
lr_output_message("==========转码前===========%s",lr_eval_string("{resultq}"));
//转码及打印结果
lr_convert_string_encoding(lr_eval_string("{resultq}"),LR_ENC_UTF8,LR_ENC_SYSTEM_LOCALE,"aftermsg");//从什么编码要转为什么编码,前为原来的编码,后为要转化成为什么编码
lr_output_message("==========转码后===========%s",lr_eval_string("{aftermsg}"));
//把转码后的结果赋值给 zuihoujieguo
lr_save_string(lr_eval_string("{aftermsg}"),"zuihoujieguo");
//lr_output_message("==========%s",lr_eval_string("{zuihoujieguo}"));
//字符串比较
//lr_output_message("%d",strcmp(lr_eval_string("{zuihoujieguo}"),"注册成功1"));
if (strcmp(lr_eval_string("{zuihoujieguo}"),"注册成功") ==0 ) //strcmp=0即为两数相同
{
lr_end_transaction("post", LR_PASS);
}else{
lr_end_transaction("post", LR_FAIL);
}
return 0;
}