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/demo2. Use -v to display detailed information about the request and response
curl -v http://localhost:8080/demo3. Use -G -d to initiate a get request and send data
curl -G -d "hello" -v http://1ocalhost:8080/demo4. Use -I to initiate a head request
curl -I http://localhost:8080/demo5. 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/actuator7.curl automatically recognizes the username and password
curl http://admin:admin@localhost:9002/actuator8. Use -u to enter only the user name and you will be prompted to enter the password
curl -u 'admin' http://localhost:9002/actuator9. Use -c to save the server response cookie
curl -u 'admin:admin' -c cookie.txt http://localhost:9002/actuator10. 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/post12. Use @reference file to contain the requested data file
curl -d @post_data -H "Content-type:application/json" http://localhost:8080/demo/post13. Use -F option post to upload files
curl -F '[email protected]'http://localhost:8080/demo/file14. Use --data-urlencode encoding to submit data
curl --data-urlencode 'name=码农小麦' -v http://localhost:8080/demo/urlencode15. Use -d to submit request data
curl -d 'AGRICULTURAL wheat code name =' -d 'Welcome to tease Content =' -v HTTP: // localhos T: 8080 / Demo / POSTThe 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.
curl -d 'AGRICULTURAL wheat code name = & content = Welcome to tease' -v http://localhos t:8080 /demo/post