Moving a site to a new server, I want to check it answers correctly under the real domain before I change DNS. Editing /etc/hosts works, but it is easy to forget to undo. curl can do it for one request.
curl -I --connect-to example.com::192.168.1.20: https://example.com/
--connect-to HOST1:PORT1:HOST2:PORT2 means: for a request meant for HOST1 on PORT1, connect to HOST2 on PORT2 instead. The port fields are left empty here, as in the example in the curl docs, so requests for example.com go to the new IP.
The important part: the curl docs say it does not change the name used for TLS, so SNI and certificate verification still use example.com. You see whether the new server presents a valid certificate for the real name, which is exactly what you want to know before the switch.
There is also --resolve example.com:443:192.168.1.20, which puts a fake DNS answer in curl’s cache for that host and port. For a quick test both work. I find --connect-to clearer, since you can also point a request at a different port.
Caveat: the host name is compared as a plain string with the one in the URL. www.example.com does not match an entry for example.com, so write the exact name you request, or add a second --connect-to for the www version.
Further reading: curl manual: –connect-to, curl manual: –resolve
Going deeper: Run degoog on Unraid as your own search page, compared with SearXNG and 4get