Random Error Indy ResponseCode = -1 / EIdSocketError Error # 0 exceptions

I have delphi code that basically uploads files to a remote secure server using 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

The problem is that the code sometimes doesn't work when Indy throws an EIdSocketError Socket Error # 0 ( idHTTP.ResponseCode is -1)

Given my crappy internet connection, I ran an instance of Windows EC2 and tested it on it (the instance of Windows is running in the cloud, so I assume the connection is not a problem), but I have the same problem!

, , , , . 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.

- , / ?

I TIdSSLIOHandlerSocketOpenSSL. googled, , SSL.

+3
1

Indy 10, 10.5.8 r4743. SSL 0 .

+1

All Articles