Doing a HTTPS connection to some site is basically done this way:
- get the IP address for the target hostname by using DNS
- connect with TCP to this IP address
- do the SSL handshake over this TCP connection, which includes
- optionally include the target hostname with the SNI extension in the start of the handshake (ClientHello). This is needed if multiple servers with different certificates share the same IP address and port.
- verify the certificate received from the server within the handshake to see if it is trusted and also if it is valid for the target hostname
- once the SSL handshake is done send the HTTP request inside this SSL connection, which includes among other things the Host header
What you effectively want is to skip the DNS lookup (step 1) because you already know the IP address of the target. You still need to all the other steps, notably 3.1 (SNI) and 3.2 (validation of hostname inside certificate).
This is possible but how this is done depends on your programming language and libraries. Most languages make only the common case easy for you (i.e. connect by hostname) and uncommon cases like yours are more complex to implement. For example in Perl you could simply use the following code to connect to a site by IP address, but include the proper SNI extension for the target hostname and also check the certificate against the hostname:
use IO::Socket::SSL 1.971;
my $socket = IO::Socket::SSL->new(
PeerAddr => '126.96.36.199:443',
SSL_hostname => 'www.example.com'
How this is done in the language of your choice is off-topic here and on-topic at stackoverflow.com.