Curl is a command line tool that sends out network requests, and then retrits and extracts data. Curl also supports file upload and download, so it is a comprehensive request transfer tool.

View the web page

View the source code

curl https://juejin.cn
curl https://juejin.im:8888
Copy the code

-l Redirects the website

curl -L https://juejin.cn
Copy the code

-o Saves the source code of the web page

Curl -o URL1 -o URL2 # -o: use the default file name in the URL to save the file to the local directory. Curl tries to reuse connections from multiple files on the same site.Copy the code

-c Breakpoint transmission

Curl - O # http://www.gnu.org/software/gettext/manual/gettext.html when files in the download is complete before end of the process the curl - C - O http://www.gnu.org/software/gettext/manual/gettext.html # by adding the -c option continue to download the file has been downloaded files will not be downloaded againCopy the code

-i Displays the response header information

Curl -i https://juejin.cn # '-i' displays the HTTP response headerCopy the code

Caught debugging

-v Displays the entire communication process for debugging

curl -v https://juejin.cn
Copy the code

— Trace requests packet capture and outputs raw binary data

Curl --trace output. TXT https://juejin.cn # original data curl --trace- ASCII output. TXT https://juejin.cn # Original data with ASCII encodingCopy the code

-s Hides or displays error information

Curl -s https://juejin.cn Displays no error information or progress information. Curl -s https://juejin.cn displays only error informationCopy the code

–limit-rate Limits the request response bandwidth, which models the network environment

Curl --limit-rate 100k https://juejin.cn # Simulation bandwidth 100K /s curl --limit-rate 200b https://juejin.cn # Simulation bandwidth 200B /sCopy the code

Simulation of the request

Send a GET request

curl https://juejin.cn
Copy the code

Send POST request –data [parameter]

Curl -x POST --data "data= XXX "https://juejin.cn curl -x POST --data "@data.json" https://juejin.cn # Send request curl-x POST --data-urlencode "data= XXX "https://juejin.cn # The arguments are form-encoded to avoid symbols being escapedCopy the code

Sending RESTful Requests

Curl -x GET https://juejin.cn # Default GET curl -x POST https://juejin.cn curl -x PUT https://juejin.cn curl -x DELETE https://juejin.cnCopy the code

–form Uploads files

curl --form upload=@[local_filepath] --form press=OK https://juejin.cn curl -F 'file=@[local_filepath]' https://juejin.cn # with --form upload=@[local_filepath] --form press=OK equivalent curl -f 'file=@[local_filepath]; Type =image/ PNG 'https://juejin.cn # The default MIME type is application/octet-streamCopy the code

–header Adds the request header information

curl --header "Content-Type:application/json" https://juejin.cn
Copy the code

– the proxy agent

curl --proxy 'https://juejin.cn' https://juejin.cn
Copy the code

Referer indicates source [anti-theft chain]

curl --referer https://juejin.cn https://juejin.cn
Copy the code

–user-agent Indicates the user device information

curl --user-agent "[User Agent]" https://juejin.cn

#The window chrome agent'the Mozilla / 5.0 (Windows NT 10.0; Win64; X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'
Copy the code

Cookie Cookie is requested

Curl --cookie "name= XXX "https://juejin.cn curl -d cookieFile https://juejin.cn # Save the cookie returned by the server to file cookieFile curl -c CookieFile https://juejin.cn # Save the cookie returned by the server to the file cookieFile curl -b cookieFile https://juejin.cn # '-b cookieFile Use the previously saved cookie file for the requestCopy the code

The -k parameter skips SSL detection

curl -k https://juejin.cn
Copy the code

Water so much finally water to “pig feet” appearance

Background children’s shoes, often encounter online interface request error need to reproduce the bug situation. At this time the normal log is not only trouble, but also easy to hit.

With curl, you can save the request with curl.

When needed, we can reproduce the bug by executing the life order, peace&love❤️

If you think my article is useful to you, please give me a thumbs up