Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

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

I have a delphi code that basically upload files to 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 sometimes the code fails with Indy throwing a EIdSocketError Socket Error # 0 exception (idHTTP.ResponseCode is -1)

Given my crappy internet connection, I launched an EC2 windows instance and tested my code on it (the windows instance is running on the cloud, so I assume connection is not a problem), yet I got the same issue!

The error seems to be random, sometimes upload works, sometimes not. I debugged with TidLogFile, all I could find is something like this:

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.

Anyone knows what's causing this/how to fix this?

EDIT

I traced the exception back to TIdSSLIOHandlerSocketOpenSSL. I googled a lot, it seems that it's not an SSL error.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Please upgrade to the latest Indy 10 version, which is 10.5.8 r4743. SSL-related issues with Error Code 0 were fixed over a year ago.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...