我有一个delphi代码,基本上使用 Indy 10.4.704 将文件上传到远程安全服务器:
IdHTTP := TIdHTTP.Create(nil);
try
TheCompressor := TIdCompressorZLib.Create(nil);
TheSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
with IdHTTP do
begin
HTTPOptions := [hoForceEncodeParams];
AllowCookies := True;
HandleRedirects := True;
ProtocolVersion := pv1_1;
IOHandler := TheSSL;
Compressor := TheCompressor;
end; // with
// Get upload resume offset
try
IdHttp.Head('https://www.domain.com/my-file.bin');
if (IdHttp.Response.ResponseCode <> 404) And (IdHttp.Response.ContentLength >= 0) then
StartPos := IdHttp.Response.ContentLength
else
StartPos := 0;
except
StartPos := 0;
end; // try/except
// Upload File
TheFile := TFileStream.Create(FileName, fmOpenRead OR fmShareDenyWrite);
RangeStream := TIdHTTPRangeStream.Create(TheFile, StartPos, -1, True);
try
if (RangeStream.ResponseCode = 206) then
IdHTTP.Post(https://www.domain.com/upload.php', RangeStream);
finally
RangeStream.Free;
end; // try/finally
finally
FreeAndNil(IdHTTP);
end; // try/finally
问题是有时代码失败,Indy抛出 EIdSocketError套接字错误#0 异常( idHTTP.ResponseCode 为-1)
鉴于我糟糕的互联网连接,我启动了EC2 windows实例并在其上测试了我的代码(windows实例在云上运行,所以我假设连接不是有问题),但我得到了同样的问题!
错误似乎是随机的,有时上传有效,有时则无效。我用TidLogFile进行了调试,我能找到的就是这样:
Stat Connected.
Sent 4/26/2012 4:18:42: POST /app/upload.php...
Sent 4/26/2012 4:18:42: <uploaded_file_data_here>
Stat Disconnected.
任何人都知道造成这种情况的原因是什么?如何解决这个问题?
修改
我traced the exception back to TIdSSLIOHandlerSocketOpenSSL。我google了很多,似乎这不是SSL错误。
答案 0 :(得分:2)
请升级到最新的Indy 10版本, 10.5.8 r4743 。与错误代码0相关的SSL相关问题已在一年前修复。