脚本开发-利用web_custom_request函数进行接口测试
by:授客 QQ:1033553122
一、POST + JSON格式参数
例:
web_custom_request("create",
"URL=http://xxx.xxx.x.xx:1600/ditui/agentshop",
"Method=POST",
"Resource=0",
"RecContentType=application/json",
"Referer=",
"Mode=HTML",
"EncType=application/json;charset=UTF-8",
"Body={"agentId":31,"contactName":"test","
""contactPhone":"18259001421","
""fullName":"赖大家家里蹲分公司1","
""shortName":"Le3JxD","
""vipEmail":"1033553122@qq.com","
""shopType":"1","
""address":"广东省深圳市宝安区华侨新村29-B座204","
""businessScope":"3","
""businessLicenseCode":"140100200567176","
""businessLicenseUrl":"2016/01/04/fcd1bde5-f64f-4aa6-82c9-82b65cd
7ccfd.jpg","
""province":"620000","
""city":"620200","
""area":"620201","
""headAddress":"广东省深圳市宝安区","
""legalName":"袁国新","
""idCard":"451202198403264276","
""idCardStartDate":"2010-10-06","
""idCardEndDate":"2020-10-06","
""idCardFrontUrl":"2016/01/06/d342b28d-c62d-416e-b947-47e47ab95d0
8.jpg","
""idCardBackUrl":"2016/01/06/f03e967a-168c-4ba6-ba99-04a3c6790bf6
.jpg","
""phoneNumber":"18259001421"}",
LAST);
运行结果:
说明:Body写法
1)参数都写在一行
"Body={"arg1":int_value1,"arg2":"str_value2",…, "argN":"valueN"}",
2)参数不都在同一行
"Body={"arg1":value1,"
""arg2":"str_value2","
""arg3":"str_value3","
……
""argN":"valueN"}",
二、POST +
非JSON格式参数
例:
web_custom_request("login",
"URL=http://127.0.0.1:1080/WebTours/login.pl",
"Method=POST",
"Resource=0",
"RecContentType=",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Mode=HTML",
"EncType=application/x-www-form-urlencoded",
"Body=userSession=117812.897691373zAzAAAApQcfDzDzApAAfff&username=jo
jo&password=bean&login.x=0&login.y=0&JSFormSubmit=off",
LAST);
运行结果:
三、GET
例:
web_custom_request("view_active_page",
"URL=http://xx.xxxxx.xxxx.cn/index.php?xx=/xxxx/Lucky/Christport/sav
e_user_info/id/726/token/84222366b2592714538e50dc69398ad7/open_id/ous64uNjaBudzU00000751vYH9k/nickname/test_user/headimgurl/testurl",
"Method=GET",
"Resource=0",
"RecContentType=Application/json",
"Referer=",
"Mode=HTML",
"EncType=application/x-www-form-urlencoded;charset=UTF-8",
"Body=",
LAST);
一个完整的例子
Join_active()
{
web_reg_save_param("result",
"LB=result":",
"RB=,"",
"NotFound=ERROR",
"Search=All",
LAST);
lr_rendezvous("join_active");
//参与抽奖
lr_start_transaction("join_active");
web_custom_request("choujiang",
"URL=http://xx.xxx.xxxx/index.php?s=/addon/Lucky/Christport/lucky/id/726/open_id/{open_id}/token/84222366b2592714538e50dc69398ad7",
"Method=GET",
"Resource=0",
"RecContentType=Application/json",
"Referer=",
"Mode=HTML",
"EncType=application/x-www-form-urlencoded;charset=UTF-8",
"Body=",
LAST);
//if(strcmp("102",lr_eval_string("{result}"))==0
|| //strcmp("103",lr_eval_string("{result}"))==0 ||
//strcmp(""21"",lr_eval_string("{result}"))==0)
if(strcmp("102",lr_eval_string("{result}"))==0 ||
strcmp("103",lr_eval_string("{result}"))==0)
{
lr_end_transaction("join_active", LR_PASS);
}else{
lr_end_transaction("join_active", LR_FAIL);
}
return 0;
}