One, get request without parameters
(1) LoadRunner script
Action ()
{
web_custom_request ("Get request",
"Url=http://localhost:8080/receivegetpost/myservlet", "Get URL address"
"Method=get",
"Resource=0",
"Referer=",
"Mode=http",
"Enctype=text/html; Charset=utf-8 ",
"Body=",
last);
return 0;
}
(2) Send request
In the Create/edit script, configure the run logic, general-vuser-> runtime settings, to fill in the number of iterations, which is the number of requests sent.
Click "Run" to start execution:
In the run load test, the scene design configures the number of users, which is the number of requests sent. Note: The Send request Test here is determined by the number of user values and the iteration count values in the run settings, for example, the number of users is 10 and the iteration count is 5, then the number of requests sent is 10*5=50.
Click "Start Scene" to start execution:
With parameters
(1) Non-parameterized LoadRunner scripts
Action ()
{
web_custom_request ("Get request",
"url=http://localhost:8080/receivegetpost/myservlet?name=xuyj&id=123456", "Get URL address"
"Method=get" ,
"Resource=0",
"Referer=",
"Mode=http",
"Enctype=text/html; Charset=utf-8 ",
"Body=",
last);
return 0;
}
The above request is sent in the same manner as a GET request without parameters.
(2) Parameterized LoadRunner script
Action ()
{
web_custom_request ("Get request",
"Url=http://localhost:8080/receivegetpost/myservlet?name=xuyj&id={newparam}", "Get URL address"
"Method=get", "id parameterization"
"Resource=0",
"Referer=",
"Mode=http",
"Enctype=text/html; Charset=utf-8 ",
"Body=",
last);
return 0;
}
(3) Send request
First, the scripting variables are parameterized:
In the Create/edit script, configure the run logic, general-vuser-> runtime settings, to fill in the number of iterations, which is the number of requests sent.
Click "Run" to start execution:
The result of the operation is: the ID value can be passed in the value of the {Newparam} parameter sequentially, which is equivalent to a user adding five times to send a GET request with a different ID value sent.
First, the scripting variables are parameterized:
In the run load test, the scene design configures the number of users, which is the number of requests sent. Note: The Send request Test here is determined by the number of user values and the iteration count values in the run settings, for example, the number of users is 2 and the iteration count is 5, then the number of requests sent is 2*5=10.
Click "Start Scene" to start execution:
The result is: Two users send five get requests independently, the ID in each request passes the value of the {Newparam} parameter sequentially, a total of 10.
Second, the POST request body parameter is not independent
(1) LoadRunner script
Action ()
{
web_custom_request ("Post test",//Name
"Method=post",// method of Request
"Url=http://localhost:8080/receivegetpost/myservlet",// Request Address
"Reccontenttype=application/octet-stream",// Specify the Content-type of the corresponding header
"Enctype=application/octet-stream",// Specifies the content-type of the request header
"Mode=html",
Raw_body_start,// The identifier for the request body start
"{\" userids\ ": [1300000001,1300002029,1300003163],\" type\ ": 0}",//body of the content
,// the length of the body content of the line above
raw_body_end,// The identifier of the request body end
last);
return 0;
}
Method for calculating the length of the body content:
- Install the Firebug plugin in Firefox.
- Open Firefox, then open the console
- In the console, enter the body content, and then use the Length property to get the string, if for the above example, it is | | "{\" userids\ ": [1300000001,1300002029,1300003163],\" type\ ": 0}". length | |, so you can calculate the result "55"
See URL http://magustest.com/blog/loadtest/json-format-request-using-loadrunner/for details
Parse: The body content in the POST request is sent to the receiver as a whole, and the parameters are not independent. Where the parameter userids and type are not parameterized in LoadRunner.
(2) Send request
It is sent in the same way as a GET request without parameters.
Body parameter Independent
(1) JMeter add POST request
The body of the POST request has UserIDs and type two independent parameters respectively
(2) Send request
Configure the send and send times in the JMeter thread group
Number of threads: equivalent to the number of users
Ramp-up period: Used to tell JMeter how long to build all the threads. The default value is 0. If ramp-up period is not specified, that is, ramp-up period is zero, JMeter will immediately establish all threads, assuming ramp-up period is set to T-second, the number of threads is set to N, and JMeter will establish a thread every t/n second.
Click "Run" to start execution:
Body with audio/video and other ancillary files
JMeter adding audio/video files
Using Loadrunner&jmeter to send Get&post request tips