使用LoadRunner进行HTTP接口性能测试

测试接口:

接口一:http://127.0.0.1/API/GroupSearch?keyword=1988&userid=00001&page=1&pagesize=100 

接口二:http://127.0.0.1/Message/SyncMessage/SendMessage

A 使用Get请求访问接口一

Action()
{

    lr_start_transaction("API_Test1");

    web_reg_find("Text=message","Search=Body","SaveCount=Count",LAST);

    web_url("API_Test1", 
        "URL=http://127.0.0.1/API/GroupSearch?keyword={keyword}&userid=00001&page=1&pagesize=100",
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t2.inf", 
        "Mode=HTML",     
         LAST);

    lr_end_transaction("API_Test1",LR_AUTO);

    return 0;
}

 

B 使用Post请求访问接口二

Action()
{

    lr_start_transaction("API_Test2");

    web_add_header("accessToken","ZJ2mJZrRndC7/RvZOZ0DB4w/cTnN4xipkK2/oLZ3+sue/BKRwcH9TJ/e6cwOiGp8/7NZh7KWR+c67xbe8i+Qiw==");

    web_custom_request("API_Test2", 
        "URL=http://127.0.0.1/Message/SyncMessage/SendMessage",
        "Method=POST",               
        "Resource=0", 
        "RecContentType=application/json;charset=UTF-8",
        "Referer=", 
        "Snapshot=t2.inf", 
        "Mode=HTTP", 
        "EncType=application/json;charset=UTF-8",
        "Body={\"userID\":\"1234\",\"ContentType\":\"1000\"}",
         LAST);
lr_end_transaction(
"API_Test2",LR_AUTO); return 0; }

上述示例中,Post请求注意Body添加格式。

posted @ 2016-07-11 17:50  ycyzharry  阅读(3131)  评论(2编辑  收藏  举报