我需要通过SSL使用Web服务。为了实现这一点,我在Delphi 6中构建了一个Web客户端,该客户端使用Indy读取客户端证书并通过https编写soap请求。该代码的编译版本是在IIS 5.0中运行的DLL。在本地计算机上测试代码后,它可以正常工作(我在代理后面)。但是,将代码部署到产品服务器(而非代理)后,SSL连接失败,提示“连接SSL出错”。

这是我的代码:

var
  Response: TStringStream;
  IdHttp: TIdHTTP;
  IdCnxSLL: TIdConnectionInterceptOpenSSL;
  XmlSoapDoc: IXMLDocument;
begin
  Response := TStringStream.Create('');
  IdHttp := TIdHTTP.Create(nil);
  IdCnxSLL := TIdConnectionInterceptOpenSSL.Create(nil);
  XmlSoapDoc := TXMLDocument.Create(nil);
  with IdCnxSLL do
   begin
    IdCnxSLL.SSLOptions.Method := sslvSSLv23;
    IdCnxSLL.SSLOptions.RootCertFile := IniHttpConnectionData.Values['RootCertFile'];
    IdCnxSLL.SSLOptions.CertFile := IniHttpConnectionData.Values['CertFile'];
    IdCnxSLL.SSLOptions.KeyFile := IniHttpConnectionData.Values['KeyFile'];
    IdCnxSLL.OnGetPassword :=  IdConInterceptOpenSSLGetPassword;
  end;
  with IdHttp do
  begin
    if bUseProxy then
    begin
       Request.ProxyServer := IniHttpConnectionData.Values['ProxyServer'];
       Request.ProxyPort := StrToIntDef(IniHttpConnectionData.Values['ProxyPort'], 0);
    end
    else
    begin
       Host := IniHttpConnectionData.Values['HTTPHost'];
       Port := StrToIntDef(IniHttpConnectionData.Values['HTTPPort'], 443);
    end;
    Request.ContentType := 'text/xml';
    Intercept := IdCnxSLL;
    InterceptEnabled := True;
  end;

  try
    IdHttp.Post(ServiceURL, SoapEnv, Response);
  except
    on E:EIdOSSLConnectError do
       LogError('SSL Connect Error: ' + E.Message);
    on E:Exception do
      LogError('Error' + E.ClassName + ' - ' + E.Message);
  end;


我也尝试将此代码编译为exe程序,并且可以正常工作。我还需要配置/添加其他内容吗?

谢谢。

最佳答案

您正在使用TIdConnectionInterceptOpenSSL的事实告诉我您正在使用非常旧的Indy版本。我猜是D6随附的Indy 8。 Indy 8和更早的版本不再由Indy开发团队(我是其成员)正式支持。您确实应该升级到Indy 9,如果没有升级到Indy 10,则在Indy 9中,TIdConnectionInterceptOpenSSL被替换为新的TIdSSLIOHandlerSocket组件。另外,Indy 9和更早版本需要定制的OpenSSL DLL,如果您为Indy版本使用了错误的DLL,这也可能导致您的错误。另一方面,Indy 10现在使用OpenSSL网站上的标准DLL。

关于delphi - Delphi 6和Indy SSL连接不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1422586/

10-10 20:03