How to Test a Website With curl: Status, Redirects, Timing, and TLS

When a website appears slow or unavailable, a browser can hide useful details behind a generic error page. The command-line tool curl lets you test the exact URL, inspect its HTTP response, follow redirects, measure connection stages, and verify TLS from the same machine where you are troubleshooting.

Start With the Status Code and Headers

A simple request such as curl -I https://example.com/ sends a HEAD request and displays response headers. Look for the HTTP status, Location on redirects, content type, caching headers, and the server date. Some applications do not handle HEAD correctly, so confirm suspicious results with a normal GET request.

To download the response body while displaying headers, use curl -i https://example.com/. If you only need the final status code, a script-friendly pattern is curl -sS -o /dev/null -w '%{http_code}\n' https://example.com/. Our guide to HTTP status codes explains what the main response classes mean.

Follow and Inspect Redirects

By default, curl reports a redirect but does not automatically request its destination. Add -L to follow redirects. Use -I -L for a quick view of the response chain, or include -w '%{url_effective}\n' to print the final URL.

Check for unexpected jumps between HTTP and HTTPS, repeated trailing-slash changes, or redirects to an old hostname. Limit automated checks with --max-redirs so a loop fails clearly instead of continuing through an excessive chain.

Test a Server Before Changing DNS

During a hosting migration, --resolve can direct a hostname and port to a chosen IP address without changing public DNS. For example, curl --resolve example.com:443:192.0.2.10 https://example.com/ connects to that address while still using the requested hostname for HTTP and TLS. This is safer and more representative than requesting an HTTPS site by IP alone.

Use the option to compare old and new servers, confirm virtual-host routing, and test the certificate before switching an A or AAAA record. Remember that it changes name resolution only for that curl command; it does not reproduce every browser, resolver, or user-network condition.

Measure Where the Time Goes

The --write-out option can separate DNS lookup, connection, TLS, first-byte, and total time. For example, print selected measurements with -w 'connect=%{time_connect} start=%{time_starttransfer} total=%{time_total}\n' while sending the body to /dev/null.

A slow connection time can suggest network or routing trouble. A large gap before the first byte often points toward application processing, database work, or an upstream dependency. Compare several runs and test from more than one network before drawing conclusions. These command-line checks complement the broader approach in our article on website monitoring beyond uptime.

Test TLS and Specific Endpoints Safely

For HTTPS, curl verifies the hostname and certificate chain by default. Do not make -k or --insecure part of a normal monitoring command because it disables important verification. A certificate failure is valuable evidence, not an obstacle to hide.

Test meaningful routes such as login, search, or a health endpoint, not only the homepage. Add --connect-timeout and --max-time so scripts stop predictably. Avoid placing passwords, tokens, or private cookies directly in shared shell history or monitoring output.

The official curl command-line manual documents the available options and all --write-out variables. A small set of repeatable curl commands can turn “the site feels slow” into precise evidence about DNS, connection setup, TLS, HTTP behaviour, and application response time.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *