Indy 10 HTTPS 代理

Indy 10 HTTPS Proxy

我这里有一个小程序,它使用 idHTTP 从 https 服务器下载一些东西。我需要更改此程序以使用 HTTPS 代理服务器。 我有两个代理的 IP 地址 1.1.1.1 8080 for HTTP 和 2.2.2.2 8084 for HTTPS .

我将我的代码修改为如下所示:

  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;

有人可以告诉我如何让 idHTTP LHandler 使用 HTTPS 代理吗?

谢谢!

您只需要单独使用 TIdHTTP.ProxyParams,并确保为其分配正确的 HTTP 代理以用于您请求的协议方案(HTTP与 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;

TransparentProxy 属性 并不像您想象的那样工作。

当您没有明确地将 TIdCustomTransparentProxy 派生的组件分配给 TransparentProxy 属性(您不是)时,属性 getter创建一个默认的 TIdSocksInfo 组件。你不想在这种情况下使用 SOCKS 代理,此外,TIdCustomTransparentProxy.Enabled 属性 是启用 TIdSocksInfo 的错误方法,你必须使用 TIdSocksInfo.Version 属性 相反。