在使用IdHTTP客户端组件时出现一般Indy错误
SOCKS5代理服务器配合使用,并使用SSL


如果我在IdHTTP代理(和非https URL)中使用SOCKS5组件,
一切正常,没有问题。
如果我将IdHTTP组件与SSL URL一起使用(并且没有SOCKS5代理),
一切正常,没有问题。
如果我将IdHTTP组件与SSL URL和SOCKS5代理一起使用,则会收到以下错误:


错误输出的Line 405
idSocks.pas (raise EIdSocksServerGeneralError.Create(RSSocksServerGeneralError);

这是我的代码

var
  HTTP            : TIdHTTP;
  Cookie          : TIdCookieManager;
  SSL             : TIdSSLIOHandlerSocketOpenSSL;
  Params          : TStringList;
  HTMLSource      : String;
  CurrentProxy    : String;
  ProxyPort       : Integer;
  ProxyHost       : String;
  ProxyUsername   : String;
  ProxyPW         : String;
begin
  Synchronize(AddItem);
  HTTP                          := TIdHTTP.Create(NIL);
  Cookie                        := TIdCookieManager.Create(HTTP);
  SSL                           := TIdSSLIOHandlerSocketOpenSSL.Create(HTTP);
  HTTP.CookieManager            := Cookie;
  HTTP.IOHandler                := SSL;
  HTTP.HandleRedirects          := True;
  Params                        := TStringList.Create;
  HTTP.Request.UserAgent        := Task^.Useragent;
  try
    while True do begin
      if terminated then Exit;
      Params.Clear;
      Cookie.CookieCollection.Clear;
      if Task^.Proxytype >= 0 then begin      // if proxy enabled
        CurrentProxy            := Task^.Form.GetProxyFromPool;
        ProxyHost               := ParsingW(':', CurrentProxy, 1);
        ProxyPort               := strtoint(ParsingW(':', CurrentProxy, 2));
        HTTP.ConnectTimeout     := (Task^.Proxytimeout * 1000);
        if Task^.ProxyAuth then begin
          ProxyUsername         := ParsingW(':', CurrentProxy, 3);
          ProxyPW               := ParsingW(':', CurrentProxy, 4);
        end;
      end;
      if Task^.Proxytype = 0 then begin //HTTP(s)
        HTTP.ProxyParams.ProxyServer      := ProxyHost;
        HTTP.ProxyParams.ProxyPort        := ProxyPort;
        if Task^.ProxyAuth then begin
          HTTP.ProxyParams.ProxyUsername  := ProxyUsername;
          HTTP.ProxyParams.ProxyPassword  := ProxyPW;
        end;
      end;
      if (Task^.Proxytype = 1) or (Task^.Proxytype = 2) then begin   // Socks 4 or 5
        SSL.TransparentProxy := TIdSocksInfo.Create(HTTP);
        (SSL.TransparentProxy as TIdSocksInfo).Port             := ProxyPort;
        (SSL.TransparentProxy as TIdSocksInfo).Host             := ProxyHost;
        if Task^.ProxyAuth then begin
          (SSL.TransparentProxy as TIdSocksInfo).Username       := ProxyUsername;
          (SSL.TransparentProxy as TIdSocksInfo).Password       := ProxyPW;
          (SSL.TransparentProxy as TIdSocksInfo).Authentication := saUsernamePassword;
        end else begin
          (SSL.TransparentProxy as TIdSocksInfo).Authentication := saNoAuthentication;
        end;
        if (Task^.Proxytype = 1) then  (SSL.TransparentProxy as TIdSocksInfo).Version := svSocks4;
        if (Task^.Proxytype = 2) then  (SSL.TransparentProxy as TIdSocksInfo).Version := svSocks5;
      end;


我是否错过了某些东西,还是无法通过Socks5代理服务器连接到SSL站点?

最佳答案

出现EIdSocksServerGeneralError的事实意味着TIdHTTP已成功与SOCKS代理通信,并且正在验证您的请求而不进行身份验证,但是随后却无法与目标服务器建立连接您在HTTPS网址中指定的网址。代理回复错误代码为1(一般故障)。确保网址正确。代理无法将主机名解析为IP(尝试在url中指定IP而不是主机名,然后查看是否有所不同),或者代理没有有效的路由来访问该IP,或者出现其他错误发生在代理端。如果您有权访问代理,请尝试查看其日志以查看实际出了什么问题。

08-26 07:07