【发布时间】:2019-01-17 02:03:48
【问题描述】:
我正在尝试在 ssl 地址服务下发帖,但连接超时 10060。我的 ssl 库和 Indy SSl 配置是正确的,因为我在使用 gmail 和其他服务发送电子邮件时使用了相同的代码。
我用邮递员发布它有效。
我的代码
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;
【问题讨论】:
-
附带说明,请勿在您的
PostData中添加Content-Type条目。该值属于TIdHTTP.Request.ContentType属性而不是:Https.Request.ContentType := 'application/x-www-form-urlencoded';,实际上您不需要手动执行此操作,因为TIdHTTP.Post()的TStrings版本会在内部为您处理。
标签: delphi ssl post indy idhttp