The curl command is used for network requests and data transfer in the terminal.
-
Send a GET request:
curl [URL]
Using the curl command plus the URL to be requested, you can send a GET request and display the response results.
-
Send POST request:
curl -X POST -d "参数" [URL]
Use
-X POST
options to specify the request method as POST, and use-d
options to specify the parameters of the POST request. -
Set request headers:
curl -H "头部信息" [URL]
Use
-H
options to set custom request headers,-H "Content-Type: application/json"
e.g. -
Save response to file:
curl -o [保存的文件名] [URL]
Use
-o
the option followed by the saved file name to save the response to a specified file. -
Follow the redirect:
curl -L [URL]
Using
-L
options, you can have curl automatically follow redirects returned by the server. -
Use a proxy:
curl -x [代理地址:端口号] [URL]
Use
-x
options to set up a proxy server for requests. -
Resumable upload:
curl -C - -T [本地文件路径] [URL]
Using
-C - -T
the option, you can resume uploading files after a breakpoint, and only upload the new part of the file. -
Download a file and show progress:
curl -O [URL]
Using
-O
the option, you can download the file to the current directory and display the download progress in the terminal.