我正在尝试在 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;
最佳答案
我有两个建议:
错误的 TLS 版本:越来越多的服务禁用 TLS 1.0 和/或 TLS1.1。默认版本为 TLS 1.0。
const DEF_SSLVERSION = sslvTLSv1; DEF_SSLVERSIONS = [sslvTLSv1];
所以添加下面一行:
IdSSL.SSLOptions.SSLVersions := [sslvTLSv1_2, sslvTLSv1_1, sslvTLSv1];
缺少 SNI 支持 ( an example for SNI )。
关于带有 Ssl 连接超时 10060 的 Delphi XE7 Indy Rest Api 帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51769847/