Curl Cheatsheet
Install php-curl on Apache on Ubuntu 20
If some plugins are not updating on your wordpress site. ensure Curl
is enabled on the server.
1
2
3
sudo apt update
sudo apt install php8.0-curl
sudo systemctl restart apache2
Confirm Curl installation
Check to see if its working in your phpinfo file
Get Website Header Responses
1
curl -I http://example.com
Find a string
To search for a specific string within the website content, you can pipe the output of curl to grep. grep is a command-line tool used for searching text patterns. For example, to search for the string “example” in the website content, you can use:
1
curl https://example.com | grep "example"
By default, grep is case-sensitive. If you want to perform a case-insensitive search, you can use the -i flag like this:
1
2
curl https://example.com | grep -i "example"
If you want to extract more specific information or format the output differently, you can use awk for more advanced text processing. For instance, to extract and print the lines containing the word “example” along with line numbers, you can use:
1
curl https://example.com | awk '/example/{print NR, $0}'
Check URL redirect is working
You can use this to check if http is redirecting to https. Or any other redirect. The response will contain the end point url.
- The location header in the response should be the https version.
- The status code should be 301 or 302
1
curl -I http://yourdomain.com
Bypass the cache
1
curl -I -H "Cache-Control: no-cache" http://yourdomain.com
older gist
install curl for php7.2
sudo apt-get install php7.2-curl
restart for change to take effect
sudo service apache2 restart
check if curl enabled on server
1
2
3
4
5
<?php
echo 'Curl: ', function_exists('curl_version') ? 'Enabled' . "\xA" : 'Disabled' . "\xA";
?>
enable curl on ubuntu
phpenmod curl
service apache2 restart
curl localhost/curl-check.php
Curl: Enabled
open result in output.txt in vim
curl https://www.example.com/serviced-office-space/ –output out.txt | vim out.txt
curl -IL https://example.com/1.pdf
Simple curl
#
Options:
-c/–cookie-jar
-b/–cookie <name=data>/
-o/–output
-O/–remote-name save file with it’s name
-#
-d/–data Also upload a file using -d @file option
-d/–data-urlencode
-d/–data-binary
-X
-G/–get explicitly make a get request
#
-C/–continue-at # curl -C - file-name continue from where left off
-F/–form uses Content-Type: multipart/form-data
-H/–header <header>
-i/–include include http header in the output
-s/–silent Make curl mute (don’t show errors or progress meter)
-T/–upload-file
-u/–user
login using username and password and save cookie to file using post request
Tip: By default, curl uses post request if you use -d/–data option
1
curl -c cookie.txt -d 'username=adi&password=secret' http://localhost/login
use previous saved cookie to navigate the site
curl -b cookie.txt http://localhost/restricted/area
get a file and save it
-# uses the progress bar instead of regular meter
curl http://localhost/some/file.js -# -o file.js
send header
example make a post request to send json data
curl -H ‘Content-Type: application/json’ -d ‘{“name”: “adi”}’ http://localhost/users