TIdHTTP 10.6.2错误:套接字错误#11001& #10051

时间:2015-07-28 13:19:49

标签: indy indy10 idhttp c++builder-xe8

我真的需要你的帮助。

我尝试在C ++ Builder XE8上使用Indy 10.6.2.5263的TIdHTTP(随XE8 Update 1提供)构建一个小型下载管理器应用程序。

但是,当目标下载地址为Socket Error #11001 - Host not found时,我总是会收到错误http://www.rarlab.com/rar/wrar53b1.exe。此外,当下载地址更改为Socket Error #10051 - Network is unreachable时,http://5.135.104.98/rar/wrar53b1.exe

我不知道为什么我总是不断收到这些错误,因为我所有其他安装的应用程序(Firefox,YM,IDM等)通常都连接到Internet。

我使用以下简单代码。

UNIT1.CPP

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DownloadClick(TObject *Sender)
{
   String FileName;
   String IB = InputBox("Download Manager", "Address", "");
   TFileStream* FStream = new TFileStream(FileName, fmCreate | fmOpenWrite);
    try
       {
        IdHTTP->ConnectTimeout = 1000;
        IdHTTP->ReadTimeout    = 1000;
        IdHTTP->Get(IB, FStream);
        ShowMessage("Download Complete");
       }
  __finally
     {
       delete FStream;
     }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdHTTPWork(TObject *ASender, TWorkMode AWorkMode, __int64 AWorkCount)
{
  if (ProgressBar->Max > 0)
  {
    DownloadStatus->Caption = IntToStr(AWorkCount) + "bytes of" + IntToStr(ProgressBar->Max) + "bytes.";
    ProgressBar->Position = AWorkCount;
  }
  else
    DownloadStatus->Caption = IntToStr(AWorkCount) + "bytes.";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdHTTPWorkBegin(TObject *ASender, TWorkMode AWorkMode, __int64 AWorkCountMax)
{
  ProgressBar->Position = 0;
  ProgressBar->Max      = AWorkCountMax;
  if (AWorkCountMax > 0)
  DownloadStatus->Caption = "Transfering: " + IntToStr(AWorkCountMax);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdHTTPWorkEnd(TObject *ASender, TWorkMode AWorkMode)
{
 if (AWorkMode != wmRead)
   return;

 DownloadStatus->Caption = "Done";
 ProgressBar->Position = 0;
}
//---------------------------------------------------------------------------

0 个答案:

没有答案