连接到WEB服务器的80端口,再发送 GET 命令
procedure TForm1.Button1Click(Sender: TObject);
begin
ClientSocket1.Host := 'delphibbs.com';
ClientSocket1.Port := 80 ;
ClientSocket1.Active := true;
end;
procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
var s:string;
begin
s:='GET /delphibbs/askqn.asp HTTP/1.1'+#13+#10;
s:= s+'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*'+#13+#10;
s:= s+'Accept-Language: zh-cn'+#13+#10;
s:=s+'Accept-Encoding: gzip, deflate'+#13+#10;
s:=s+'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)'+#13+#10;
s:=s+'Host: delphibbs.com'+#13+#10;
s:=s+'Connection: Keep-Alive'+#13+#10;
s:=s+ #13+#10; //不能少
// 有些行可以省略,但上一行的换行不能少
ClientSocket1.Socket.SendText(s);
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
begin
memo1.Text := Socket.ReceiveText;
end;