23 May 2019

Debug Web Resources using curl command

Debug Web Resources using curl Command

Basic usage, request URL content or/and headers:
curl https://www.example.com/     # returning content of a URL
curl -I https://www.example.com/  # returning only the HTTP headers of a URL
curl -i https://www.example.com/  # returning both the HTTP headers and content of a URL    
Saving the result of a curl command into file:
curl -O https://www.example.com/css/style.css             # keep file name
curl -o mystyle.css https://www.example.com/css/style.css # set custom file name
Adding an additional HTTP header(s):
curl -H "Authorization: Basic YWRtaW46YWRtaW4=" https://www.example.com/admin
Change user agent with curl:
curl -A "i-m-not-a-bot" https://www.example.com/
# or
curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; FSL 7.0.6.01001)" https://www.example.com/
Post data to URL using curl:
curl -d '{"key01":"value01", "key02":"value02"}' \
     -X POST -H "Content-Type: application/json" https://www.example.com/
Getting curl to output HTTP status code:
curl -s -o /dev/null -w "%{http_code}" https://www.example.com/
Check "time to first byte" for URL:
curl -w "Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total} \n" \
     -s -o /dev/null -H 'Cache-Control: no-cache' https://www.example.com/
cURL command description:

curl is a tool to transfer data from or to a server, using one of the supported protocols (HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE). The command is designed to work without user interaction.

manpage: linux.die.net