带有 Ssl 连接超时 10060 的 Delphi XE7 Indy Rest Api 帖子

标签 delphi ssl post indy idhttp

我正在尝试在 ssl 地址服务下发帖,但连接超时 10060。我的 ssl 库和 Indy SSl 配置是正确的,因为我在使用 gmail 和其他服务发送电子邮件时使用了相同的代码。

我用 postman 发帖了。

我的代码

const
  Api = 'https://xxxx.xxxx.com/api/detection/Insert';

procedure TRestSender.SendThreats(CustomerId: Integer;
  DetectionName, Filename: String);
var
  PostData: TStringList;
  res: string;
  Https: TIdHttp;
  IdSSL: TIdSSLIOHandlerSocketOpenSSL;
begin
  Https := Tidhttp.Create(nil);
  PostData := TStringList.Create;
  IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  Https.ReadTimeout := 10000;
  Https.ConnectTimeout:= 10000;

  IdSSL.SSLOptions.Method := sslvTLSv1;
  // IdSSL.OnStatusInfo:= ssl1StatusInfo;
  IdSSL.SSLOptions.Mode := sslmClient;
  Https.IOHandler := IdSSL;
  try
    PostData.Add('Content-Type:application/x-www-form-urlencoded');
    PostData.Add('CustomerId=' + IntToStr(CustomerId));
    PostData.Add('DetectionName=' + DetectionName);
    PostData.Add('DeviceName=' + ComputerName());
    PostData.Add('Filename=' + Filename);
    PostData.Add('ApiUser=' + 'some-code');
    PostData.Add('ApiPass=' + 'some-paswd');
    res := Https.Post(Api, PostData);
  finally
    PostData.Free;
    Https.Free;
    IdSSL.Free;
  end;
end;

最佳答案

我有两个建议:

  1. 错误的 TLS 版本:越来越多的服务禁用 TLS 1.0 和/或 TLS1.1。默认版本为 TLS 1.0。

    const
      DEF_SSLVERSION = sslvTLSv1;
      DEF_SSLVERSIONS = [sslvTLSv1];
    

    所以添加下面一行:

    IdSSL.SSLOptions.SSLVersions := [sslvTLSv1_2, sslvTLSv1_1, sslvTLSv1];
    
  2. 缺少 SNI 支持 ( an example for SNI )。

关于带有 Ssl 连接超时 10060 的 Delphi XE7 Indy Rest Api 帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51769847/

相关文章:

firefox - Selenium:如何确保 back() 导航在不同站点上按预期工作?

delphi - SetRoundMode(rmUp) 并将 "round"值舍入为 10,结果为何为 10,0001?

ssl - 使用 Golang 在 Nginx 后面运行的 GRPC 服务的 TLS

amazon-web-services - 将 Namecheap 域添加到 AWS Elastic Beanstalk

objective-c - CFNetwork SSLHandshake 失败 (-9810) 问题 (Objc)

javascript - React Native中如何从TextField获取值,由于空值导致无法将数据存储到数据库

html - Coldfusion 中的柱形多维数组

delphi - Delphi中从TWebRequest获取文件

delphi - 如何找到丢失的TActionList

image - 在 Delphi 中将透明和拉伸(stretch)图像添加到图像列表