Delphi中随机Indy响应码为-1时,如何解决套接字错误问题?

2026-04-28 01:153阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计357个文字,预计阅读时间需要2分钟。

Delphi中随机Indy响应码为-1时,如何解决套接字错误问题?

我有一段Delphi代码,基本使用Indy+10.4.704将文件上传到远程安全服务器:`IdHTTP :=TIdHTTP.Create(nil); try TheCompressor :=TIdCompressorZLib.Create(nil); TheSSL :=TIdSSLIOHandlerSocketOpenSSL.Create(nil); with IdHTTP do begin`

我有一个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('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(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.

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

编辑

Delphi中随机Indy响应码为-1时,如何解决套接字错误问题?

我traced the exception back to TIdSSLIOHandlerSocketOpenSSL.我google了很多,似乎这不是一个SSL错误.

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

本文共计357个文字,预计阅读时间需要2分钟。

Delphi中随机Indy响应码为-1时,如何解决套接字错误问题?

我有一段Delphi代码,基本使用Indy+10.4.704将文件上传到远程安全服务器:`IdHTTP :=TIdHTTP.Create(nil); try TheCompressor :=TIdCompressorZLib.Create(nil); TheSSL :=TIdSSLIOHandlerSocketOpenSSL.Create(nil); with IdHTTP do begin`

我有一个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('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(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.

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

编辑

Delphi中随机Indy响应码为-1时,如何解决套接字错误问题?

我traced the exception back to TIdSSLIOHandlerSocketOpenSSL.我google了很多,似乎这不是一个SSL错误.

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