我真的再次需要你的帮助。
我尝试在 C++ Builder XE8 上使用 Indy 10.6.2.5263 的 TIdHTTP(随 XE8 更新 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;
}
//---------------------------------------------------------------------------