本文介绍了随机Indy ResponseCode = -1 / EIdSocketError Socket错误#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;
协议版本:= pv1_1;

IOHandler:= TheSSL;
压缩器:= TheCompressor;
结束// with

//获取上传简历偏移量
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;
除了
StartPos:= 0;
结束// try / except

//上传文件
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;
结束// try / finally
finally
FreeAndNil(IdHTTP);
结束// try / finally

问题是有时代码失败Indy抛出一个 EIdSocketError Socket错误#0 异常( idHTTP.ResponseCode 为-1)



连接,我推出了一个EC2 Windows实例,并测试了我的代码(Windows实例在云上运行,所以我假设连接不是一个问题),但我有同样的问题! p>

错误似乎是随机的,有时上传工作,有时不是。我使用TidLogFile调试,我可以找到这样的东西:

  Stat Connected。 
发送4/26/2012 4:18:42:POST /app/upload.php ...
发送4/26/2012 4:18:42:< uploaded_file_data_here>
Stat Disconnected。

任何人都知道导致这个/如何解决这个问题?



编辑



我。我已经很多了,似乎这不是一个SSL错误。

解决方案

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


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.

解决方案

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.

这篇关于随机Indy ResponseCode = -1 / EIdSocketError Socket错误#0异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 02:19