Curl: Difference between revisions
Jump to navigation
Jump to search
Line 25: | Line 25: | ||
Option #2: (will convert connection of example.com to altexample.com) <ref>https://serverfault.com/questions/443949/how-to-test-a-https-url-with-a-given-ip-address</ref> | Option #2: (will convert connection of example.com to altexample.com) <ref>https://serverfault.com/questions/443949/how-to-test-a-https-url-with-a-given-ip-address</ref> | ||
curl --connect-to example.com:80:altexample.com:80 http://example.com | curl --connect-to example.com:80:altexample.com:80 http://example.com | ||
# shorthand: | |||
curl --connect-to ::altexample.com:80 http://example.com | |||
Option #3: | Option #3: |
Revision as of 15:17, 9 June 2025
Return status code only
curl -s -o /dev/null -w "%{http_code}" google.com
curl -s -o /dev/null -i -w "%{http_code}" google.com
curl -s -o /dev/null -I -w "%{http_code}" google.com
curl -s -o /dev/null -I -w "%{http_code}\n" google.com
ref: [1]
Return fail status code
curl --fail http://some-url.com echo $?
-f, --fail (HTTP) Fail silently (no output at all) on server errors
Connect to server by ip and pass hostname
Option #1:
- Add to C:\windows\system32\drivers\etc\hosts
Option #2: (will convert connection of example.com to altexample.com) [2]
curl --connect-to example.com:80:altexample.com:80 http://example.com # shorthand: curl --connect-to ::altexample.com:80 http://example.com
Option #3:
curl --resolve <host:port:address> <URL> host: The hostname you want to use in the request. port: The port number for the connection. address: The IP address you want to connect to. URL: The URL you want to request, using the specified hostname.
curl --resolve example.com:443:192.168.1.100 https://example.com
- "This command will send a request to the IP address 192.168.1.100, but it will include example.com in the Host header, which is crucial for virtual hosting and TLS/SSL certificate validation."
Option #4: (this does not seem to work??)
curl [IP] -k -H 'Host: example.com'