#curl #linux #Windows #commandline #cmd #shell ![[CURLCommands.jpeg]] Curl commands (markontech.com).sh # Basic cURL Usage ``curl http://example.com`` # Fetch a webpage ``curl -L http://example.com`` # Follow redirects ``curl -I http://example.com`` # Fetch headers only ``curl -o output.html http://example.com`` # Save response to a file ``curl -0 http://example.com/file.txt`` # Save file with original name # HTTP Methods ``curl -X GET http://example.com curl -X POST http://example.com`` # Perform a GET request (default) ``curl -X PUT http://example.com`` # Perform a PUT request ``curl -X POST http://example.com`` # Perform a POST request ``curl -X DELETE http://example.com`` # Perform a DELETE request # Sending Data with Requests ``curl -d "param1=value1&param2=value2" -X POST http://example.com`` # Send form data ``curl -d @data.json -X POST http://example.com`` # Send JSON data from a file ``curl -H "Content-Type: application/json" -d '{"name":"John"} -X POST http://example.com`` # Send JSON inline # Sending Headers ``curl -H "User-Agent: CustomUserAgent" http://example.com`` # Set a custom User-Agent ``curl -H "Authorization: Bearer mytoken" http://example.com`` # Send authentication token ``curl -H "Accept: application/json" http://example.com`` # Request JSON response # Handling #Authentication ``curl -u username: password http://example.com`` # Basic authentication ``curl --basic -u user:pass http://example.com`` # Explicitly use basic authentication ``curl --digest -u user:pass http://example.com`` # Digest authentication ``curl --ntlm -u user:pass http://example.com`` # #NTLM authentication # Handling #Cookies ``curl -b cookies.txt http://example.com`` # Send cookies from a file ``curl -c cookies.txt http://example.com`` # Save received cookies to a file ``curl -b "name=value" http://example.com`` # Send cookies #inline # Downloading Files ``curl -0 http://example.com/file.zip`` # Download a file with its original name ``curl -o custom_name.zip http://example.com/file.zip`` # Download file and rename curl -C ``curl -C - -0 http://example.com/file.zip`` # Resume an interrupted download # Uploading Files ``curl -T file.txt ftp://example.com/`` # Upload a file to #FTP ``curl -T file.txt -u user:pass ftp://example.com/`` # Upload with authentication ``curl -F "[email protected]" http://example.com/upload`` # Upload file with #multipart form # #Debugging & #Verbose Output ``curl -v http://example.com`` # Verbose output (see request/response headers) ``curl -i http://example.com`` # Show #ResponseHeaders ``curl -s http://example.com`` # Silent mode (no progress output) ``curl --trace trace.txt http://example.com`` # Save request/response #trace to a file ``curl --trace-ascii trace.txt http://example.com`` # #ASCII only trace file # Rate Limiting & Timeout ``curl --limit-rate 100k http://example.com/file.zip`` # Limit #DownloadSpeed ``curl --max-time 10 http://example.com`` # Timeout after 10 seconds ``curl --connect-timeout 5 http://example.com`` # Timeout if connection takes more than 5 seconds # #Proxy Usage ``curl -x socks5://proxy:port http://example.com`` # Use a #SOCKS5 proxy ``curl -x http://proxy:port http://example.com`` # Use an #HTTP proxy ``curl --proxy-user user:pass -x http://proxy:port http://example.com`` # Proxy authentication # Handling #SSL & #Certificates ``curl -k https://example.com`` # Ignore SSL certificate errors ``curl --cacert ca.pem https://example.com`` # Use a custom CA certificate ``curl --cert client.pem --key client.key https://example.com`` # Use client certificate authentication 66 curl --ssl-reqd ftp://example.com/ # Require SSL/TLS for FTP # Working with #API 's ``curl -H "Content-Type: application/json" -X POST -d '{"user":"john"}' http://api.example.com # Send JSON payload curl -H "Authorization: Bearer TOKEN" http://api.example.com`` # Use an API token ``curl -G -d "search-query" http://api.example.com/search`` # Send GET request with query parameters # #Piping Output ``curl http://example.com | grep "text"`` # Search response for text ``curl -s http://example.com | ją . # Pretty-print #JSON response using #jq ``curl -s http://example.com | tee output.txt`` # Save and display response # #IPv4 & #IPv6 ``curl -4 http://example.com`` # Force IPv4 ``curl -6 http://example.com`` # Force IPv6 # #Parallel #Requests ``curl -Z http://example.com/file1 http://example.com/file2`` # Download multiple files in parallel ``curl -0 http://example.com/file1 -0 http://example.com/file2`` # Download multiple files sequentially # HTTP #Compression ``curl --compressed http://example.com`` # Request compressed response (#gzip, #deflate) # Custom #RequestHeaders ``curl -H "Referer: http://google.com" http://example.com`` # Set #RefererHeader ``curl -H "Cache-Control: no-cache" http://example.com`` # Disable #caching ``curl -A "Mozilla/5.0" http://example.com`` # Fake #UserAgent #Mozilla # Testing Websites for #HTTPMethods ``curl -X OPTIONS http://example.com`` # Check allowed HTTP methods ``curl -X TRACE http://example.com`` # Perform an HTTP TRACE request ``curl -X HEAD http://example.com`` # Fetch #Headers only # Measuring Response Time & Performance ``curl -w "@format.txt" -o /dev/null -s http://example.com`` # Custom output formatting ``curl -o /dev/null -s -w "Time: %{time_total}\n" http://example.com`` # Measure response time ``curl -o /dev/null -s -w "DNS Lookup: %{time_namelookup}s\nConnect: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n" http://example.com`` # Full #Breakdown # Follow #Redirects & Preserve Cookies ``curl -L -c cookies.txt -b cookies.txt http://example.com`` # Follow redirects and store cookies # Handling FTP ``curl -u user:pass ftp://example.com/file.txt`` # #Download a file via FTP ``curl -u user:pass -T file.txt ftp://example.com/`` # #Upload a file via FTP ``curl -u user:pass ftp://example.com/ -Q "DELE file.txt"`` # #Delete a file via FTP # Running in #Background #bg ``curl -o /dev/null -s http://example.com &`` # Run in background [[Download an Open Directory on the internet]] [[_BOOKMARKS_DOWNLOADS]] [[Download a Facebook Video]] [[Yourls, Install and Configure]]