The Curl command simulates an HTTP Get/post request

Source: Internet
Author: User

When testing the backend program, you need to make a mock connection or write a test script.

Curl is a great command.

For example, destination site URL:
127.0.0.1:8080/check_your_status?user=summer&passwd=12345678
Request via Get Method:
Curl Protocol://address:port/url?args
Curl http://127.0.0.1:8080/check_your_status?user=Summer&passwd=12345678
Request via POST method:
curl-d "args" "Protocol://address:port/url"
Curl-d "user=summer&passwd=12345678" "Http://127.0.0.1:8080/check_your_status"
This method is the parameter directly inside the header
If you want to specify the output to a file, you can do so by redirecting it.
Curl-h "Content-type:application/json"-X POST--data (json.data) URL
Curl-h "Content-type:application/json"-X POST--data ' {"message": "Sunshine"} ' http://localhost:8000/
The method is that the JSON data is directly inside the body.

To view the request response time method using the Curl command
Curl-o/dev/null-s-W%{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total}::%{speed_download } "\ n" http://www.36nu.com

0.014::0.015::0.018::0.019::1516256.00

-O: Write the HTML and JS returned by Curl to the garbage collection station [/dev/null]
-S: Remove all States
-W: Write the RT in the following format
Time_namelookup:dns parsing the time of the domain name www.36nu.com
Time_commect:client and server end time to establish TCP connections
Time_starttransfer: A request from the client; the server in the Web responds to the first byte of time
Time_total:client sends a request to the Web server to send all the corresponding data time
Speed_download: Next week speed Unit byte/s
The above command and the return result can be understood as follows:
0.014:dns the time unit of the server parsing www.36nu.com is s
0.015:client the time that a request is made to C/s to establish TCP, including the time of DNS resolution
0.018:client the time at which the first byte of a response is emitted, including the previous 2 time
0.019:client sends a request, to S to send the response data all to the client, and to turn off the connect time
1516256.00: Speed of downloading data
Establish TCP connection to server when the client first byte is returned: 0.018s–0.015s = 0.003s
Time the server sent response data to client: 0.019s–0.018 = 0.01s

The Curl command simulates an HTTP Get/post request

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.