Indy组件 TCPClient 访问 网页
百度IP 202.108.22.5,
与服务端链接成功后,服务端发送百度首页的源代码,但是客服端接收不到,一直跑空,如果服务端发送的是别的数据(123456)或者字符串(我我我我我我),接收正常
读取数据用的 TCPClient->ReadLn();
新手,望高人指导
[解决办法]
双引号不是什么问题,用转义符反斜杠。
[解决办法]
哪个IP地址换了?Server还是Client?
在TCPServer里更改属性影响到了TCPClient?
[解决办法]
你要这样做的,最简单的 IdTCPClient 获取 HTTP 页面内容
IdTCP->Host = "202.108.22.5";
IdTCP->Port = 80;
IdTCP->Connect();
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;
String S;
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, TEncoding::Default);
// S 就是接收到的页面内容
}