Difference between revisions of "CURL"

From Indie IT Wiki
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
https://curl.haxx.se
 
https://curl.haxx.se
 +
 +
== Test Web Site Speed Performance Using Curl ==
 +
 +
curl -s -w 'Testing Website Response Time for %{url_effective}\n\nLookup Time:\t\t%{time_namelookup}\nConnect Time:\t\t%{time_connect}\nAppCon Time:\t\t%{time_appconnect}\nRedirect Time:\t\t%{time_redirect}\nPre-transfer Time:\t%{time_pretransfer}\nStart-transfer Time:\t%{time_starttransfer}\n\nTotal Time:\t\t%{time_total}\n' -o /dev/null <nowiki>https://www.bbc.co.uk</nowiki>
 +
 +
Testing Website Response Time for <nowiki>https://www.bbc.co.uk</nowiki>
 +
 +
Lookup Time: 0.015612
 +
Connect Time: 0.022144
 +
AppCon Time: 0.082065
 +
Redirect Time: 0.000000
 +
Pre-transfer Time: 0.082170
 +
Start-transfer Time: 0.485600
 +
 +
Total Time: 0.511278
  
 
== Using Variables ==
 
== Using Variables ==
Line 17: Line 32:
 
...so that the shell can expand the variable.
 
...so that the shell can expand the variable.
  
For example, calling the GANDI Live DNS API to update a record for fish.mydomain.com using your public IP address...
+
For example, calling the [https://api.gandi.net/docs/livedns/ GANDI Live DNS API] to update a record for fish.mydomain.com using your public IP address...
  
 
  export MYIP=$( curl -s ifconfig.me ) && curl -s -X PUT -H "Content-Type: application/json" -d '{"rrset_values":['"\""${MYIP}"\""']}' -H "Authorization: Apikey xxxxxxxxxxxxxxxxxxxxxxxx" <nowiki>https://api.gandi.net/v5/livedns/domains/mydomain.com/records/fish/A</nowiki>
 
  export MYIP=$( curl -s ifconfig.me ) && curl -s -X PUT -H "Content-Type: application/json" -d '{"rrset_values":['"\""${MYIP}"\""']}' -H "Authorization: Apikey xxxxxxxxxxxxxxxxxxxxxxxx" <nowiki>https://api.gandi.net/v5/livedns/domains/mydomain.com/records/fish/A</nowiki>
Line 36: Line 51:
  
 
  curl -O URL
 
  curl -O URL
 +
 +
== Output Web Page As Plain Text ==
 +
 +
curl -s <nowiki>https://www.google.co.uk/</nowiki> | pandoc -f html -t plain
  
 
== Follow Redirection With Details ==
 
== Follow Redirection With Details ==

Latest revision as of 13:27, 2 October 2024

A command line tool for transferring data with URLs.

https://curl.haxx.se

Test Web Site Speed Performance Using Curl

curl -s -w 'Testing Website Response Time for %{url_effective}\n\nLookup Time:\t\t%{time_namelookup}\nConnect Time:\t\t%{time_connect}\nAppCon Time:\t\t%{time_appconnect}\nRedirect Time:\t\t%{time_redirect}\nPre-transfer Time:\t%{time_pretransfer}\nStart-transfer Time:\t%{time_starttransfer}\n\nTotal Time:\t\t%{time_total}\n' -o /dev/null https://www.bbc.co.uk

Testing Website Response Time for https://www.bbc.co.uk

Lookup Time:		0.015612
Connect Time:		0.022144
AppCon Time:		0.082065
Redirect Time:		0.000000
Pre-transfer Time:	0.082170
Start-transfer Time:	0.485600

Total Time:		0.511278

Using Variables

You have to use double double quotes and escape the ones you need!

If you want to end up with an IP address in quotes...

"123.456.78.90"

... it has to be written as

"\""${MYIP}"\""

...so that the shell can expand the variable.

For example, calling the GANDI Live DNS API to update a record for fish.mydomain.com using your public IP address...

export MYIP=$( curl -s ifconfig.me ) && curl -s -X PUT -H "Content-Type: application/json" -d '{"rrset_values":['"\""${MYIP}"\""']}' -H "Authorization: Apikey xxxxxxxxxxxxxxxxxxxxxxxx" https://api.gandi.net/v5/livedns/domains/mydomain.com/records/fish/A

SNI

Server Name Identification is the method of requesting a partuclar host on a shared server, to make sure you request the correct SSL Certificate.

The curl option 'resolve' allows you to specify which IP address to resolve the domain name to, great for testing an Let's Encrypt SSL Certificate...

curl -vik --resolve domain.org.uk:443:172.17.0.2 https://domain.org.uk

POST

curl -X POST -F 'ip=23.129.64.235' https://www.zerospam.org/wp-json/v1/query

Output To File

curl -O URL

Output Web Page As Plain Text

curl -s https://www.google.co.uk/ | pandoc -f html -t plain

Follow Redirection With Details

curl --insecure --verbose --location URL

Manual

https://curl.haxx.se/docs/manual.html