Search code examples
httpdelphihttpsproxyindy

Indy 10 HTTPS Proxy


I have a small program here that uses idHTTP to download some things from a https server . I need to alter this program to use a HTTPS Proxy server . I got two IP addresses for the proxy 1.1.1.1 8080 for HTTP , and 2.2.2.2 8084 for HTTPS .

I altered my code to look like this :

  try
   IdHTTP1:=TIdHTTP.Create(nil);
   try
    LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
    try
      // does not seem to do anything
      LHandler.TransparentProxy.Host:='2.2.2.2';
      LHandler.TransparentProxy.Port:=8084;
      LHandler.TransparentProxy.Enabled:=true;

      // this works even when using HTTP proxy for HTTPS
      idHTTP1.ProxyParams.ProxyServer:='1.1.1.1';
      idHTTP1.ProxyParams.ProxyPort:=8080;


      IdHTTP1.IOHandler:=LHandler;
      Src:= IdHTTP1.Get('https://csv.business.tomtom.com/extern?account='+company+'&username='+user+'&password='+password+'&apikey='+apikey+'&lang=en&action=showObjectReportExtern');
    finally
      LHandler.Free;
    end;
   finally
     IdHTTP1.Free;
   end;
  except on E: Exception do
//      Writeln(E.ClassName, ': ', E.Message);
  end;

Can someone please show me how do I tell idHTTP LHandler to USE the HTTPS Proxy ?

Thank you!


Solution

  • You need to use ONLY the TIdHTTP.ProxyParams by itself, and be sure to assign it the correct HTTP proxy to use for the protocol scheme you are requesting (HTTP vs HTTPS):

    try
      IdHTTP1 := TIdHTTP.Create(nil);
      try
        LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP1);
        IdHTTP1.IOHandler := LHandler;
    
        IdHTTP1.ProxyParams.ProxyServer := '2.2.2.2';
        IdHTTP1.ProxyParams.ProxyPort := 8084;
    
        Src := IdHTTP1.Get('https://csv.business.tomtom.com/extern?account='+company+'&username='+user+'&password='+password+'&apikey='+apikey+'&lang=en&action=showObjectReportExtern');
      finally
        IdHTTP1.Free;
      end;
    except
      on E: Exception do
        // Writeln(E.ClassName, ': ', E.Message);
    end;
    

    The TransparentProxy property does not work the way you think it does.

    When you do not explicitly assign a TIdCustomTransparentProxy-derived component to the TransparentProxy property (which you are not), the property getter creates a default TIdSocksInfo component. You do not want to use a SOCKS proxy in this situation, and besides, the TIdCustomTransparentProxy.Enabled property is the wrong way to enable a TIdSocksInfo, you have to use the TIdSocksInfo.Version property instead.