web_custom_request 

LR帮助文档的定义

Allows you to create a custom HTTP request with any method supported by HTTP. 
Allows you to create a custom HTTP request using any method or body. By default, VuGen generates this function only for requests that could not be interpreted with other web functions.

 int web_custom_request( const char *RequestName, <List of Attributes>,[EXTRARES, <List of Resource Attributes>,] LAST ); 

web_custom_request()函数是一个可以用于自定义http请求的“万能”函数。页面的提交方式,POST、GET、PATCH、PUT等。

 

数据提交形式:

A、post+JSON格式参数:

1)参数都写在一行: "Body={"arg1":int_value1,"arg2":"str_value2",…, "argN":"valueN"}",

2)参数不都在同一行

"Body={"arg1":value1,"

        ""arg2":"str_value2","

        ""arg3":"str_value3","

         ……

        ""argN":"valueN"}",

 

B、post+非JSON格式参数:

 “Body=属性名称=属性值&属性名称=属性值&……”

 

示例:

web_custom_request(
……
"BodyUnicode=REPRICE"
"BodyBinary=\\x08\\x00\\xCC\\x02\\x00\\x00"
"Body=.\r\n"
"-dxjjtbw/(.tp?eg:ch/6--\r\n",
LAST);

不同的应用中,请求体分别通过Body、BodyBinary或者BodyUnicode参数来传递。请求体可以只使用其中一个参数,也可以使用一连串的分开的参数组成多请求体。

在上面的代码中,使用了3个参数来划分请求体,一个是Unicode,一个是二进制,最后一个是常规的字符串。最终的请求体是这3个参数按照在函数中的顺序连接起来的值。还有一个很少用到的参数,Binary。它也能描述二进制请求体,但只允许函数中只有一个请求体参数。所有的请求体都是ASCII字符,以null结束。

它也可以使用二进制字符串。 

char *abc= .../* a pointer to the raw data */ 
web_custom_request("StepName", 
"URL=http://some.url ", 
"Method=POST", 
RAW_BODY_START, 
"abc", 
3, 
RAW_BODY_END, 
LAST); 

 

   当使用web_custom_request()函数来发送http的get和post请求时,如果未使用web_add_header相关函数来自定义添加头部,请求中带有默认的http请求头部字段

web_url("file.html", "URL=http://lazarus/html/forms/file.html", "TargetFrame=_TOP", LAST ); 

web_add_header("Content–Type","multipart/form–data; boundary=–––––––––––––––––––––––––––292742461228954"); 

web_custom_request("post_query.exe", "Method=POST", 
    "URL=http://lazarus/cgi–bin/post_query.exe", 
    "Body=–––––––––––––––––––––––––––––292742461228954\r\nContent–Disposition: form–data; name=\"entry\"\r\n\r\nText\r\n–––––––––––––––––––––––––––––292742461228954\r\nContent–Disposition: f–––––––––––292742461228954––\r\n", 
    "TargetFrame=", 
    LAST ); 

如需要修改默认的头部字段或增加其他头部字段就在web_custom_request()函数的前面使用web_add_header()函数来添加

如果要减少某个头部字段或全部自动添加的头部字段就在web_custom_request()函数的前面使用web_remove_auto_header()和web_revert_auto_header(),头部字段所有请求中公共的一些头部可以放在web_add_auto_header()函数中,配合web_add_header系列函数来完成自定义的业务脚本。 

 

转自Loadrunner 关联 web_custom_request综合实例 的一个实例。

Loadrunner 关联web_custom_request,针对自带的订票系统的一个综合实例,相信看了本文大家对学习loadrunner脚本会有很大的帮助.
本实例要解决的问题:
(1)动态删除Loadrunner订票系统的一条订单;
(2)动态判断表单订单条目,执行取消第一条订单;
(3)Loadrunner关联 
web_custom_request以及循环语句的应用。
代码不足之处:变量定义太多,希望和大家共同交流。
以下为我的脚本的源码:
------------------------------------------------------
#include "web_api.h"
 
Action()
{
int i,k;
char form[1024];
char temp[1024];
char 
tmp[1024];
char tp[1024];
char tp1[1024];
char 
tp2[1024];
 
 web_url("MercuryWebTours",
     "URL=http://192.168.8.9/MercuryWebTours/",
     "Resource=0",
     "RecContentType=text/html",
     "Referer=",
     "Snapshot=t1.inf",
     "Mode=HTML",
     LAST);
 lr_think_time(10);
 web_submit_form("login.pl",
     "Snapshot=t2.inf",ITEMDATA,
     "Name=username","Value=zhangming", ENDITEM,
     "Name=password","Value=666666", ENDITEM,
     "Name=login.x", "Value=50",ENDITEM,
     "Name=login.y", "Value=11",ENDITEM,
     LAST);
 lr_think_time(4);
  
 web_reg_save_param("flightID",
     "LB=INPUT TYPE=\"hidden\" NAME=\"flightID\"VALUE=\"",
     "RB=\"",
     "ORD=ALL",
     "search=body",
     LAST);
 
 web_image("Itinerary Button",
     "Alt=Itinerary Button",
     "Snapshot=t3.inf",
     LAST);
      
strcpy(form,"Body=1=on");
i=atoi(lr_eval_string("{flightID_count}"));
for(k=1;k<=i;k++)
 {
sprintf(temp,"{flightID_%d}",k);
 
strcpy(tmp,lr_eval_string(temp));//取出flightID的值,并把值传给tmp
 
sprintf(tp,"&flightID=%s",tmp);
 
strcat(form,tp);
}
 
for(k=1;k<=i;k++)
 {
sprintf(tp2,"&.cgifields=%d",k);
strcat(tp1,tp2);
 }
strcat(form,tp1);
strcat(form,"&removeFlights.x=137&removeFlights.y=13");
 
lr_output_message("form 
的值为=%s",form);
web_custom_request("itinerary.pl",
     "url=http://192.168.8.9/MercuryWebTours/itinerary.pl",
     "Method=POST",
     "RecContentType=text/xml",
     form,
     "Snapshot=t7.inf",
     LAST);
return 0;
}
View Code

相关文章:

  • 2021-08-29
  • 2021-09-03
  • 2018-09-11
  • 2021-07-23
  • 2022-12-23
  • 2021-04-12
猜你喜欢
  • 2021-10-15
  • 2022-12-23
  • 2022-02-27
  • 2021-06-12
  • 2021-08-10
相关资源
相似解决方案