首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

loadrunner通过web的post请求方法测接口

loadrunner通过web的post请求方法测接口

loginapi()

{

web_url("rest",

"URL=http://192.168.117.154/router/rest",

"Resource=0",

"RecContentType=text/html",

"Referer=",

"Snapshot=t1.inf",

"Mode=HTML",

LAST);

web_url("favicon.ico",

"URL=http://192.168.117.154/favicon.ico",

"Resource=0",

"RecContentType=text/html",

"Referer=",

"Snapshot=t2.inf",

"Mode=HTML",

LAST);

lr_rendezvous("loginapi");

lr_start_transaction("loginapi");

lr_set_debug_message(LR_MSG_CLASS_EXTENDED_LOG | LR_MSG_CLASS_RESULT_DATA, LR_SWITCH_ON );

web_reg_find("Text=操作成功",

LAST);

web_submit_data("testpost",

"Action=http://192.168.117.154/router/rest",

"Method=POST",

"RecContentType=text/html",

"Mode=HTML",

ITEMDATA,

"Name=method","Value=test.user.UserService.userInfoByTicket",ENDITEM,

"Name=v","Value=1.0",ENDITEM,

"Name=app_key","Value=120",ENDITEM,

"Name=ticket","Value=1111111111111111111111111111111",ENDITEM,

"Name=sign","Value=22222222222222222222222222222222",ENDITEM,

LAST);

lr_set_debug_message(LR_MSG_CLASS_EXTENDED_LOG | LR_MSG_CLASS_RESULT_DATA, LR_SWITCH_OFF);

lr_end_transaction("loginapi", LR_AUTO);

return 0;

}

模拟APP发送请求给Cloud,

一般都是用户登录后。cloud会返回登录成功的消息并且返回一个cookie给app,

app下次要做一些例如设置名称之类的工作,在请求消息里面会携带返回的cookie,而且cloud也会校验这个cookie

1、第一次请求登录,获取cookie,

2、使用第一次请求获取的cookie进行第二次请求

Action()

{

web_reg_save_param("par1",

"LB=auth_key\":\"",

"RB=\"",

LAST);

web_reg_save_param("par3",

"LB=Set-Cookie: ",

"RB=;",

"ORD=2",

LAST);

web_custom_request("login",

"URL=http://192.168.1.102/api/user/login",

"Method=POST",

"Resource=0",

"Referer=",

"mode=HTTP",

"Body=email=333@163.com&password=8c2b2f9cd3431be8a7bf64a33e81b371",

LAST);

lr_message ("par1:%s", lr_eval_string(""));

lr_message ("par3:%s", lr_eval_string(""));

return 0;

}

Action2()

{

web_cleanup_cookies();

web_add_header("cookie",

";");

web_custom_request("info",

"URL=http://192.168.1.102/api/app/set/device",

"Method=POST",

"Resource=0",

"Referer=",

"mode=HTTP",

"Body=cid=4026aabc&auth_key=",

LAST);

return 0;

}

传json数据时引号前加转义字符\

"Name=input","Value={\"mobile\":\"15280288288\",\"password\":\"6f96c57e306923c7\"}",ENDITEM,

  • 发表于:
  • 原文链接http://kuaibao.qq.com/s/20180315G1E8KN00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券