Jump to content

Adressing IP with System.Net.HttpClient

Recommended Posts

Hi there,


I need to request my server using its IP, not a domain name. The problem is that an IP can't have a SSL certificate.


So I have an error about the need of a certificate with this code :




procedure TForm1.Button1Click(Sender: TObject);
  serveur: THTTPClient;
  serveur_reponse: IHTTPResponse;
  post_param: TMultiPartFormData;

  serveur := THTTPClient.Create;
  post_param := TMultiPartFormData.Create;

  serveur_reponse := serveur.post('', post_param);

  if serveur_reponse.StatusCode = 200 then





Tghis code runs fine with a classic URL, but not with the IP.


How can I use THTTPClient and say it not to check certificates ?


Share this post

Link to post

have you tried "serveur_reponse := serveur.post('', post_param)" ?

Share this post

Link to post

What is the error?

I guess you have in fact an https/TLS error: the certificate is for the domain name, and you use the IP which doesn't match the certificate.
So the request is rejected.
Try to relax the HTTPS certification validation.

Share this post

Link to post

Yes it's exactly that. But how can I do, then, to address my server with its IP ????


What do you mean with : Try to relax the HTTPS certification validation.

Share this post

Link to post
Posted (edited)



the Indy suite is @Remy Lebeau area, then, he can help for sure. find it here on forum members. 

Note: same that THTTPclient is not from Indy suite.



Edited by Guest

Share this post

Link to post

In general, I could see this working if you connect the underlying TCP socket to the desired IP address, and then have the TLS handshake use the SNI extension to specify the desired domain name as the target for the certificate, and also have HTTP send a "Host" header specifying the same domain name.  But I don't know if/how this can be done with THTTPClient, though.  It is not doable with Indy's TIdHTTP (without hacking its source code) since everything uses the same hostname/IP specified in the URL.

Share this post

Link to post
Posted (edited)

Disable server verification. IDK how to do it with THTTPClient but you have the subject to search for.

With Windows secure sockets I done this


  // starting TLS handshake
  if sfNoServerVerify in SessionData.Flags then
  // before starting TLS
  if FAddrIsIP then
      SChannelLog(loSslInfo, Format(S_Msg_AddrIsIP, [Addr]));
      Include(FSessionData.Flags, sfNoServerVerify);
  // after successful handshake
    // Don't pass host addr if it's IP otherwise verification would fail
    if FAddrIsIP then
        CheckServerCert(FhContext, '')
        CheckServerCert(FhContext, Addr);

In cURL this option is called "insecure"

       -k, --insecure
              (TLS) By default, every SSL connection curl makes is verified to
              be secure. This option allows curl to proceed and  operate  even
              for server connections otherwise considered insecure.

              The  server  connection  is verified by making sure the server's
              certificate contains the right name  and  verifies  successfully
              using the cert store.

              See this online resource for further details:
              See also --proxy-insecure and --cacert.


Edited by Fr0sT.Brutal

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now