delphi – Random Indy ResponseCode = -1 / EIdSocketError套接字错误#0异常

我有一个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错误.

最佳答案 请升级到最新的Indy 10版本,即10.5.8 r4743.与错误代码0相关的SSL相关问题已在一年前修复.

点赞