Use the curl command of the simulation request tool

Common simulation request tools

1 nc: tcp/udp protocol transmission

2 curl: http request

3 postman

4 Agent tools, IDE tools, browser plug-in tools

curl command use

1. Example:

url=http://www.baidu.com

get method

curl $url

post method

curl -X --data 'xxx' $url

proxy way

curl -x 'http://127.0.0.1:8080' $url

2. Common parameters

-H "Content-Type:application/json": message header setting
-u username:password: user authentication
-d @file file
–data-urlencode'page_size=50': url-encode the content
-G: treat data as get parameters sent the request, often combined with urlencode--data
-o: write file
-x: agent
-X: specify additional request, the default GET, such as POST, DELETE
-v: print a more detailed log
-s: Close some hints output
- i: display response header information + webpage source code
-I: display response header information only
-L: automatically jump to a new URL
-v: display the entire process of an http communication, including port connection and http request header information
-trace: view More detailed communication process-
form: specify form information
-user-agent: specify client device information-
cookie: send cookie
-c cookie-file: save the cookie returned by the server to a file
-b cookie-file: use this file as a cookie information

3. Common examples

1. View the webpage source code
curl www.sina.com

2. Save to the file
curl -o [file name] www.sina.com

3. Automatically jump to the new URL
curl -L www.sina.com

4. Display the header information of http response
curl -i www.sina.com

5. View more detailed communication process
curl --trace output.txt www.sina.com

6. Form file upload
curl --form upload=@localfilename --form press=OK [URL]

7. Specify the device information
iPhone4 User Agent:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/ 6531.22.7
curl --user-agent “[User Agent]” [URL]

8. Increase the header information
curl --header "Content-Type:application/json" http://example.com

Guess you like

Origin blog.csdn.net/dabaoting/article/details/115047731