Tips and trick using curl

Categories: linux webserver

Download files

curl -O https://test.example.com/madplan.json
curl -O -L http://test.example.com/madplan.json # Follows links. In this example the http request will be redirected to https
curl -o test.json https://test.example.com/test.json # Saves the file as test.json
 

Send host header

Usefull when the server is hosting multiple domains

curl -H "host: test.example.com" http://172.16.0.150

 

Show host headers

curl -I http://test.example.com

HTTP/2 200 
server: openresty
date: Fri, 18 Aug 2023 11:03:58 GMT
content-type: text/html
content-length: 1543
last-modified: Fri, 18 Aug 2023 10:54:36 GMT
etag: "64df4dec-607"
accept-ranges: bytes
 

Force dns resolution

This can be really usefull when testing configuration before making any changes to DNS.

curl https://test.example.com --resolve test.example.com:443:172.16.0.150