1,317
社区成员
发帖
与我相关
我的任务
分享
void __fastcall TNSService::IdTCPServerConnect(TIdContext *AContext)
{
AContext->Connection->IOHandler->DefStringEncoding = TIdTextEncoding::Default;
}
void __fastcall TForm1::IdTCPClient1Connected(TObject * ASender)
{
IdTCPClient1->IOHandler->DefStringEncoding = TIdTextEncoding::Default;
}
TIdTCPClient * IdTCP = new TIdTCPClient(this);
IdTCP->Host = "127.0.0.1"; // 可以是域名
IdTCP->Port = 80;
UnicodeString S = "/XML/GetSoftXML.asp?Software=WinRAR";
S += "&Ident=121515";
S += "&LangId=" + IntToHex((int)GetSystemDefaultLCID(),4);
try
{
IdTCP->IOHandler->WriteLn("GET " + S + " HTTP/1.1");
IdTCP->IOHandler->WriteLn("Host: " + IdTCP->Host);
IdTCP->IOHandler->WriteLn("Accept: text/html, */*");
IdTCP->IOHandler->WriteLn("Accept-Encoding: identity");
IdTCP->IOHandler->WriteLn("User-Agent: Mozilla/3.0 (compatible; Indy Library)");
IdTCP->IOHandler->WriteLn("Connection: Keep-Alive");
IdTCP->IOHandler->WriteLn();
bool HttpOK = false;
int ResponseLen = 0;
do
{
S = IdTCP->IOHandler->ReadLn();
if (S == "HTTP/1.1 200 OK") HttpOK = true;
else if (S.Pos("Content-Length:") == 1)
{
S.Delete(1, S.Pos(" "));
ResponseLen = S.ToIntDef(0);
}
}
while (S.Length());
if (HttpOK && ResponseLen)
{
S = IdTCP->IOHandler->ReadString(ResponseLen);
XMLDocument1->XML->Add(S);
}
if (IdTCP->IOHandler->InputBuffer->Size)
IdTCP->IOHandler->InputBuffer->Clear();
IdTCP->Disconnect();
XMLDocument1->Active = true;
}
catch (...) { }
delete IdTCP;