IdHTTP + SOCKS +袜子5

use*_*785 9 delphi ssl proxy indy

IdHTTP客户端组件与SOCKS5代理服务器结合使用时,我遇到了一般的Indy错误SSL.

  • 如果我使用IdHTTP我的SOCKS5代理组件(和非https URL),一切都可以正常工作.
  • 如果我使用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;
Run Code Online (Sandbox Code Playgroud)

我是否遗漏了某些内容,或者是否无法使用Socks5代理连接到SSL站点?

Rem*_*eau 6

您获得一个EIdSocksServerGeneralError凸起的意思TIdHTTP是成功与SOCKS代理通信,它正在验证您的访问请求而没有身份验证,但是它无法与您在HTTPS网址中指定的目标服务器建立连接.代理正在回复错误代码1(一般失败).确保网址准确无误.代理无法将主机名解析为IP(尝试在URL中指定IP而不是主机名,看看它是否有所不同),或者代理没有到达该IP的有效路由,或者其他一些错误是发生在代理端.如果您有权访问代理,请尝试查看其日志以查看实际出现的问题.

  • 你能写一个 ssl +ocks5 的例子吗?我给了你赏金:) (2认同)