LoadRunner中涉及到向服务器发送请求的API方法包括:web_url(), web_submit_form(), web_submit_data(), web_custom_request(), 下面介绍两种我常用的方法:
方法一:使用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);
这也是一种写法,可以跟web_submit_data互换,这种写法更利于拼接参数
方法一适合一些xml结构的根元素下的子元素同处于根元素下面,且子元素数目较少的情况下,如果xml结构比较复杂,
比如说根元素下面有很多子元素,或者xml树结构分叉较多的时候,我们可用先把xml拼接成一个字符串然后通过web_custom_request()向服务器发送请求。
* 以上内容摘抄自百度文库
我常用web_url()函数进行接口测试