One of the most useful command line tools which I have come across is CURL.
In this blog, I will mention some of ways we can make use of curl. I will keep adding more as and when I learn.
- You can use -I paramter to get the HTTP response code, headers etc. The browsers can cache data so sometimes you are not sure if tha response is from the cache. With curl from command line, you’re sure.
curl https://www.wikipedia.org/ -I
HTTP/1.1 200 OK
Date: Fri, 26 Mar 2021 08:26:46 GMT
Cache-Control: s-maxage=86400, must-revalidate, max-age=3600
Server: ATS/8.0.8
ETag: W/"10483-5be1dab9caf01"
Last-Modified: Mon, 22 Mar 2021 10:38:46 GMT
Content-Type: text/html
Vary: Accept-Encoding
Age: 31310
X-Cache: cp5009 hit, cp5009 hit/111166
X-Cache-Status: hit-front
Server-Timing: cache;desc="hit-front", host;desc="cp5009"
Strict-Transport-Security: max-age=106384710; includeSubDomains; preload
Report-To: { "group": "wm_nel", "max_age": 86400, "endpoints": [{ "url": "https://intake-logging.wikimedia.org/v1/events?stream=w3c.reportingapi.network_error&schema_uri=/w3c/reportingapi/network_error/1.0.0" }] }
NEL: { "report_to": "wm_nel", "max_age": 86400, "failure_fraction": 0.05, "success_fraction": 0.0}
Set-Cookie: WMF-Last-Access=26-Mar-2021;Path=/;HttpOnly;secure;Expires=Tue, 27 Apr 2021 12:00:00 GMT
Set-Cookie: WMF-Last-Access-Global=26-Mar-2021;Path=/;Domain=.wikipedia.org;HttpOnly;secure;Expires=Tue, 27 Apr 2021 12:00:00 GMT
X-Client-IP: 49.207.200.163
Set-Cookie: GeoIP=IN:KA:Bengaluru:12.96:77.59:v4; Path=/; secure; Domain=.wikipedia.org
Accept-Ranges: bytes
Content-Length: 66691
Connection: keep-alive
- Did you know you could send many requests using a single curl command? Here’s how:
curl -I https://www.wikipedia.org?[1-100]
- You can measure the time taken for the server to respond using cURL:
curl -s -o /dev/null -w "%{time_total}\n" https://bing.com
To look at the break-down of the total time using cURL, you can use this:
1.Create a file named curl-format.txt and add the following contents:
time_namelookup: %{time_namelookup}s\n
time_connect: %{time_connect}s\n
time_appconnect: %{time_appconnect}s\n
time_pretransfer: %{time_pretransfer}s\n
time_redirect: %{time_redirect}s\n
time_starttransfer: %{time_starttransfer}s\n
----------\n
time_total: %{time_total}s\n
2.Make a request:
curl -w "@curl-format.txt" -o /dev/null -s "http://wordpress.com/"