Using Loadrunner&jmeter to send Get&post request tips

Source: Internet
Author: User

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

    • Method One:

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:

    • Method Two:

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

    • Method One:

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.

    • Method Two:

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:

    1. Install the Firebug plugin in Firefox.
    2. Open Firefox, then open the console
    3. 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

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.