Web_custom_request Application Examples

Source: Internet
Author: User
Tags list of attributes ord

Web_custom_request Application Examples

The Web_custom_request function provided by LoadRunner can be used to implement dynamic generation of parameters. In LoadRunner, Web_reg_save_param and custom_request are often used to handle dynamic generation of parameters.

The Web_reg_save_param function is familiar to everyone, and its main function is to get the data from a response for subsequent request, and then save it as a parameter for subsequent steps to use. This method is called correlation (Association) in LoadRunner.

The Web_custom_request function can be used to fully customize the request sent to the server.

Next we use a practical example to illustrate the specific application of Web_custom_request:

Taking Mercury's own mercurywebtours example, let's say we want to delete the first two records of the user after login, and we'll see how this can be achieved with web_custom_request.

First, we try to record the operation in HTML. The sections in the recorded script that are related to deletions are as follows:

Web_url ("welcome.pl",
"Url=http://localhost/mercurywebtours/welcome.pl?page=itinerary",
"Resource=0",
"Reccontenttype=text/html",
"Referer=http://localhost/mercurywebtours/nav.pl?page=menu&in=home",
"Snapshot=t3.inf",
"Mode=html",
Extrares,
"Url=images/in_itinerary.gif", "Referer=http://localhost/mercurywebtours/nav.pl?page=menu&in=itinerary", Enditem,
"Url=images/home.gif", "Referer=http://localhost/mercurywebtours/nav.pl?page=menu&in=itinerary", ENDITEM,
last);
Lr_think_time (2);

Web_submit_form ("itinerary.pl",
"Snapshot=t4.inf",
ItemData,
"Name=1", "Value=on", Enditem,
"name=2", "Value=on", Enditem, "name=removeflights.x", "value=116", Enditem,
"Name=removeflights.y", "value=8", Enditem,
last);

We look at the content of the request actually made to the server when the submit form is in the tree mode:

As can be seen from the request content, we send a request through the Post method, the destination URL of the request is/mercurywebtours/itinerary.pl, the content is sent:
"1=on&flightid=384-798-jm&2=on&flightid=3026-1592-jm&3=on&flightid=1194-2326-jm& Cgifields=1&.c "
"Gifields=2&.cgifields=3&removeflights.x=116&removeflights.y=8"

From the sent content can be very obvious analysis, 1=on that the first checkbox is selected, FLIGHTID=384-798-JM represents the first record of the corresponding Flightid. Therefore, if we need to compose this request, we must first obtain the Flightid of the first two records in a related way, and then compose the content of the request.

The prototype of the Web_custom_request method is:
int web_custom_request (const char *requestname, <list of Attributes>,[extrares, <list of Resource Attributes> ;,] last);

The main items of list of attributes are Method,url and body etc. For this example, we can easily construct the body content of the request we need.
......
strcpy (Creq, "body=1=on&flightid=");
strcat (Creq, lr_eval_string ("{fID1}"));
strcat (Creq, "&2=on&flightid=");
strcat (Creq, lr_eval_string ("{fID2}"));
strcat (Creq, "&.cgifields=1&.cgifields=2");
strcat (Creq, "&removeflights.x=116&removeflights.y=8");
......

where {fID1}, {fID2}, and so on are all Flightid data obtained by association.

Therefore, we can write Custom_request statements based on the data in the diagram:

Web_custom_request ("itinerary.pl",
"Method=post",
"Url=http://localhost/mercurywebtours/itinerary.pl",
"Reccontenttype=text/xml",
Creq,
"Snapshot=t4.inf",
last);


The more complete code is as follows:

Action ()
{
CharCREQ[500];

Web_reg_save_param ("FID1", "Lb=input type=\" hidden\ "name=\" flightid\ "value=\" "," rb=\ "", "ord=1",
"Search=body", last);
Web_reg_save_param ("FID2", "Lb=input type=\" hidden\ "name=\" flightid\ "value=\" "," rb=\ "", "ord=2",
"Search=body", last);
Web_url ("welcome.pl",
"Url=http://localhost/mercurywebtours/welcome.pl?page=itinerary",
"Resource=0",
"Reccontenttype=text/html",
"Referer=http://localhost/mercurywebtours/nav.pl?page=menu&in=home",
"Snapshot=t3.inf",
"Mode=html",
Extrares,
"Url=images/in_itinerary.gif", "Referer=http://localhost/mercurywebtours/nav.pl?page=menu&in=itinerary", Enditem,
"Url=images/home.gif", "Referer=http://localhost/mercurywebtours/nav.pl?page=menu&in=itinerary", ENDITEM,
last);
Lr_think_time (2);

strcpy (Creq, "body=1=on&flightid=");
strcat (Creq, lr_eval_string ("{fID1}"));
strcat (Creq, "&2=on&flightid=");
strcat (Creq, lr_eval_string ("{fID2}"));
strcat (Creq, "&.cgifields=1&.cgifields=2");
strcat (Creq, "&removeflights.x=116&removeflights.y=8");

Lr_output_message (Creq);

Web_custom_request ("itinerary.pl",
"Method=post",
"Url=http://localhost/mercurywebtours/itinerary.pl",
"Reccontenttype=text/xml",
Creq,
"Snapshot=t4.inf",
last);

return0;
}

Web_custom_request Application Examples

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.