Loadrunner之HTTP接口测试


  接口测试的原理是通过测试程序模拟客户端向服务器发送请求报文,服务器接收请求报文后对相应的报文做出处理然后再把应答报文发送给客户端,客户端接收应答报文这一个过程。测试http接口和测试webservice接口一样,需要开发提供相关接口及参数说明,当然如果条件不允许,我们也可以通过IE浏览器插件httpwatch或者火狐浏览器的firebug等工具来捕获操作中的参数传递情况。接口参数说明如下:

接口测试地址:/cas/login

请求报文参数说明:

请求报文格式:

<?xml version="1.0" encoding="ISO-8859-1"?>
< Publish >
  <SNSID>123</SNSID>
  <UserID>456</ UserID >
  <CommentsTypeID>2</ CommentsTypeID >
  <CommentsID>123</CommentsID>
  <AuthorID>456</AuthorID>
  <CommentsContent>Don't forget the meeting!</CommentsContent >
</Publish>

应答报文的参数接口说明:

<?xml version="1.0" encoding="ISO-8859-1"?>
< Publish >
  <UserID>456</ UserID >
  <CommentsTypeID>2</ CommentsTypeID >
  <CommentsID>123</CommentsID>
  <CommentsContent>Don't forget the meeting!</CommentsContent >
  <StatusCode>0</StatusCode>
  <StatusText>发送成功一条评论</StatusText>
</Publish>

 

根据文档的描述在LoadRunner书写相应的接口测试脚本。

一、使用web_submit_data()

web_submit_data("insert",
"Action=http://116.211.23.123/SNS/Publish.htm ",
"Method=POST", 
"Referer=http://116.211.23.123/SNS/Publish.htm ",
"Mode=HTML",
ITEMDATA,
"Name= SNSID ","Value=6601",ENDITEM,
"Name= UserID ","Value=123",ENDITEM,
"Name= CommentsTypeID ","Value=1",ENDITEM,
"Name= CommentsID ","Value=456",ENDITEM,
"Name= AuthorID","Value=789",ENDITEM,
"Name= CommentsContent ","Value=Just for testing",ENDITEM,
LAST);

二、使用web_custom_request()

char str[1000];
strcpy(str,"SNSID=7999&UserID=1&CommentsTypeID=1&CommentsID=1&AuthorID=1&CommentsContent=1");
web_custom_request("Publish",
"Url= http://116.211.23.123/SNS/Publish.htm",
"Method=POST",
"Referer=http://116.211.23.123/SNS/Publish.htm ",
"Mode=HTTP",
str,
LAST);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值