JMeter Testing HTTP Requests

Source: Internet
Author: User

HTTP Hypertext Transfer Protocol (hypertext Transfer Protocol) is one of the most widely used network protocols on the Internet. All WWW documents must comply with this standard. (See the Encyclopedia for more information)

HTTP send requests have get,post,put, Option,head,delete,trace,connect 8 kinds, the most common is the GET, POST and PUT request, the other is relatively rare.

1, get: Used to do not modify the data only to the server to obtain resources (such as our common access to a site home page, access to a screen ah ...) Basic use of Get request mode)

2. Post: Used to submit data to the server and obtain the processing results returned by the server (such as login to a Web site, registration and so on are generally used POST request mode)

The difference between get and post: In fact get can do the Post method is basically can do, see your server side how to deal with. The big difference between the two is that the GET request puts all the request parameters in the request Lu Jingli (such as Http://e.dangdang.com/classification_list_page.html?category=YXJJ &dimension=sale&order=0, the following three parameters and values: Category=yxjj&dimension=sale&order=0 are in the road strength, and post will put the parameters in the body to submit , the benefits of doing so are mainly as follows:

A, GET request parameters in the road, if too many parameters will cause the URL is too long, and each browser URL length has its own restrictions (such as the chrome 8182 characters ie limit up to 2083 ...) If the limit is exceeded, then the request fails, and the POST request body does not have this limitation;

B, GET request parameters are placed in the path anyone visiting the website can see your parameter value at a glance ... This is not safe, easy to cause information disclosure, such as login requests, if you use GET, the user's password displayed in the URL, people see at a glance

3, put: Usually used to send requests to the server and can also submit data, put is similar to post.

[OK more HTTP request content please refer to the encyclopedia]

Let's go on to introduce how to use JMeter to send HTTP requests to test the HTTP protocol interface. The detailed steps are as follows:

Open JMeter, right-click Test Plan, create a new thread group:

Right-click the thread group--Add an HTTP Sampler:

The interface documentation We are testing here assumes the following:

1.HTTP Interface 1:jmeter Test GET request for HTTP form parameters

Request Address: Http://api.nnzhp.cn/getuser
Request Method: GET
Interface entry: UserID (form parameter)

Return format:{"Age": +, "code": $, "id": "1", "name": "Xiaoming "}

The JMeter configuration is as follows:

OK, the script is ready to go, then add a listener: View the results tree for easy viewing of the results of the operation:

Next look at the other interface:

2.HTTP Interface 2:jmeter Test the POST request for HTTP JSON incoming parameters

Request Address: Http://api.nnzhp.cn/getmoney

Request Method: POST

Request entry: UserID (JSON)

Return format: {' Code ': $, ' userid ': 1, ' Money ': 1000}

The HTTP request script in JMeter is configured as follows:

The results of the operation are as follows:

Then look at an interface:

3.HTTP interface 3:jmeter Test headers header information Content-type Application/json HTTP request

Request Address: Http://api.nnzhp.cn/getuser2

Request Method: POST

Request Header: Content-type:application/json

Request entry: UserID

Result format:{' Code ': 200,id ': 1, ' name ': ' Xiaoming ', ' age ':

The JMeter request is configured as follows:

After you write the HTTP request, right--add a configuration component to the HTTP request header:

Fill in the header information:

Run the View results:

4.HTTP Interface 4:jmeter test HTTP requests with cookies:

Request Address: Http://api.nnzhp.cn/setmoney2

Request Method: POST

Request parameters: UserID Money form parameter "need to add cookie-->token=token12345"

Return format: {' Code ': $, ' success ': ' Success '}

The script is configured as follows:

It is necessary to note that the cookie itself is sent in the HTTP request, so here JMeter the cookie in the HTTP header manager when adding the cookie for the HTTP request:

To view the results of a run:

5.Jmeter test HTTP request upload file:

Request Address: Http://api.nnzhp.cn/uploadfile

Request Method: POS

Request parameters: File (Files)

Return result: {' code ': $, ' success ': ' Success '}

The JMeter script is configured as follows:

Note that when uploading a file using JMeter, you need to check: use Multipart/form-data for POST or specify in MIME type: Multipart/form-data

To view the results of a run:

OK, common HTTP request scripts are basically just these kinds of classes.

JMeter Testing HTTP Requests

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.