代码之家  ›  专栏  ›  技术社区  ›  user1937012

Indy 10 HTTPS代理

  •  0
  • user1937012  · 技术社区  · 7 年前

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

    我把代码改成这样:

      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代理吗?

    谢谢您!

    1 回复  |  直到 7 年前
        1
  •  3
  •   Remy Lebeau    7 年前

    你只需要使用 TIdHTTP.ProxyParams 一个人,一定要把它 对的 用于您请求的协议方案的HTTP代理(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;
    

    这个 TransparentProxy 财产并不像你想象的那样运作。

    当您没有显式指定 TIdCustomTransparentProxy -派生组件到 透明氧 属性(您不是),属性getter创建一个默认值 TIdSocksInfo 组件。在这种情况下,您不想使用SOCKS代理,而且 TIdCustomTransparentProxy.Enabled 属性是启用 蒂德索克辛福 ,您必须使用 TIdSocksInfo.Version 取而代之的是财产。