[Http] Still using postman? Does curl not smell

What is curl? c can be regarded as a client, and url (Uniform Resource Locator) is a uniform resource locator. Curl can perform network transmission for the specified URL. It is so convenient, powerful and reliable in shells and scripts.

Curl supports n multi-protocols (ftp, smtp, etc.). This article only discusses related topics related to http based on the command line. Using curl can easily replace graphical interface tools such as postman. Let's look at using curl to initiate an http request.

1. Initiate an http get request

curl http://localhost:8080/demo
2. Use -v to display detailed information about the request and response
curl -v http://localhost:8080/demo
3. Use -G -d to initiate a get request and send data
curl -G -d "hello" -v http://1ocalhost:8080/demo
4. Use -I to initiate a head request
curl -I http://localhost:8080/demo
5. Use -i to respond with header information
curl -i http://localhost:8080/demo
----The
above is a basic get request example, let's look at using curl to initiate a request that requires login authentication.
6. Use -u to provide username and password
curl -u 'admin:admin' http://localhost:9002/actuator
7.curl automatically recognizes the username and password
curl http://admin:admin@localhost:9002/actuator
8. Use -u to enter only the user name and you will be prompted to enter the password
curl -u 'admin' http://localhost:9002/actuator
9. Use -c to save the server response cookie
curl -u 'admin:admin' -c cookie.txt http://localhost:9002/actuator
10. Use -b to carry cookie information to initiate an http request
curl -b cookie.txt http://localhost:9002/actuator
----
Let’s take a look at using curl to send a post request.
11. Use -d to send http post request data -H to specify the head line header information
curl -d "{'name':'star','age':20}" -H  "Content-type:application/json"  http://localhost:8080/demo/post
12. Use @reference file to contain the requested data file
curl -d @post_data -H "Content-type:application/json" http://localhost:8080/demo/post
13. Use -F option post to upload files
curl -F '[email protected]'http://localhost:8080/demo/file
14. Use --data-urlencode encoding to submit data
curl --data-urlencode 'name=码农小麦' -v http://localhost:8080/demo/urlencode
15. Use -d to submit request data
curl  -d  'AGRICULTURAL wheat code name ='  -d  'Welcome to tease Content ='  -v HTTP: // localhos T: 8080 / Demo / POST 
curl  -d  'AGRICULTURAL wheat code name = & content = Welcome to tease'  -v http://localhos t:8080 /demo/post
The above are examples of common command-line usage of curl, which can fully cope with daily development and test scenarios, as well as script-related http request functions. For more usage methods, see curl --help.


Guess you like

Origin blog.51cto.com/15060464/2638260