2012-11-05 37 views
1

當我有一個基本下載從一個安全的服務器文件(使用印建立10.5.8 r4743如果我沒有記錯的話)這個Delphi代碼:(印)TIdHTTP EIdSocketError套接字錯誤#0例外下載文件

的問題是:我收到隨機「套接字錯誤#0」的異常,我無法得到解決,甚至瞭解:

Project MyProject.exe raised exception class EIdSocketError with message 'Socket Error # 0

Stack is here,帕斯卡代碼:

IdHTTP   := TIdHTTP.Create(nil); 
TheSSL   := TIdSSLIOHandlerSocketOpenSSL.Create(nil); 
TheCompressor  := TIdCompressorZLib.Create(nil); 
TheCookieManager := TIdCookieManager.Create(IdHTTP); 

try SetupWebComponents(IdHTTP, TheSSL, TheCompressor, TheCookieManager); except end; 

TheCookieManager.OnNewCookie := MainForm.SyncNewCookie; 

// Go! 
Stream   := TMemoryStream.Create; 
try 
    IsError  := False; 
    try 
     with IdHTTP do 
     begin 
      OnWork    := MainForm.IdHTTPWork_Download; 
      try 
       try 
       IsNewFile  := (Not FileExists(LocalFile)); 
       if IsNewFile then 
        TheFile  := TFileStream.Create(LocalFile, fmCreate) 
       else 
        // File already exist, resume download 
        TheFile  := TFileStream.Create(LocalFile, fmOpenReadWrite); 

       DoExit   := False; 

       // Use [ Request.Referer ] it to pass VersionGUID to Work event (to record download progress in db) 
       Request.Referer := VersionGUID; 
       repeat 
         // Get resume byte 
         if IsNewFile then 
         begin 
          ResumeByte := 0; 
          IsNewFile := False; 
         end 
         else 
          ResumeByte := GetResumeByteFromDB(); 

         if FileExists(LocalFile) then 
         begin 
          // File already exist, resume download 
          DoExit  := (ResumeByte >= TheFileSize); 
          TheFile.Seek(ResumeByte, soFromBeginning); 
         end; 

         // Save ResumeByte, it will be used to record download progress in db & eventually use it to resume downloads) 
         IdHTTP.Tag  := ResumeByte; 

         Request.Range := IntToStr(ResumeByte) + '-'; 

         Get(TheURL, TheFile); 
         IsError   := (Not (ResponseCode in [200, 206])) OR (Pos('login', URL.Document) <> 0); 

         // Break if there's any error (to allow retrying later in a clean fashion) 
         if IsError then 
          Break; 
       until DoExit; 

       Disconnect; 
       except 
        if (ResponseCode = 404) then 
        begin 
         // File doesn't exist, get out 
         Result  := False; 
         Exit; 
        end; 
       end; // try/except 
      finally 
        FreeAndNil(TheFile); 
      end; // try/finally 
     end; // with 
    except 
     IsError := True; 
    end; // try/except 
finally 
     Stream.Free; 
end; 

posted a similar question some time ago,但那是關於上傳,不下載。從那時起,在SO成員的幫助下,代碼得到了修復,現在正在使用相同的代碼(用於處理cookie,重新登錄等),所以我假設問題確實存在於下載過程中以上

有人可以看看這個告訴我我做錯了什麼嗎?

回答

2

就像您的other question一樣,如果可能的話,您應該升級到更新的版本,並在請求幫助之前驗證問題是否仍然存在。當前版本是10.5.9 r4861

+0

謝謝雷米。 FWIW,Indy下載頁面混淆不清,只是提醒自己/任何處於相同位置的人,** [真正的**下載鏈接](http://indy.fulgan.com/ZIP/) ...我會嘗試使用最新版本,看看我是否仍然有這個問題,謝謝! – TheDude

+0

好的,我剛剛升級,現在我得到這個異常:'項目blabla.exe引發異常類EIdOSSLUnderlyingCryptoError消息'錯誤連接SSL。 錯誤:14094410:SSL例程:SSL3_READ_BYTES:sslv3 alert handshake failure'.'我不確定這是什麼意思,我的SSL是有效的,我確定。 – TheDude

+0

恕我直言,下載頁面沒有混淆,它是準確和直接的,它只需要幾個鏈接來找到實際的下載鏈接,就這些。在下載之前有很多信息要傳達給用戶。 –