【问题标题】:Indy 10 HTTPS ProxyIndy 10 HTTPS 代理
【发布时间】:2018-08-01 06:22:39
【问题描述】:

我这里有一个小程序,它使用 idHTTP 从 https 服务器下载一些东西。我需要更改此程序以使用 HTTPS 代理服务器。 我有两个代理的 IP 地址 1.1.1.1 8080 用于 HTTP 和 2.2.2.2 8084 用于 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 代理?

谢谢!

【问题讨论】:

    标签: http delphi https proxy indy


    【解决方案1】:

    您只需要单独使用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 属性。

    【讨论】:

    • 非常非常非常感谢。我用谷歌搜索和搜索,真的很困惑 :) 但现在我想起来了。当我创建这个 idHTTP 时,我要么使用 HTTP 要么使用 HTTPS,而不是两者。因此,如果我使用 HTTPS,我会使用 HTTPS 代理 IP 和端口。
    猜你喜欢
    • 2017-05-21
    • 2012-10-28
    • 2012-04-30
    • 2013-04-28
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    • 2011-01-15
    • 1970-01-01
    相关资源
    最近更新 更多