完全用WINSOCK写的,以http://www.21cn.com/为例:
var
len,s:integer;
name:sockaddr_in;
he
HostEnt;
buf:array[0..1023]of char;
str,data:string;
wsd:WSADATA;
begin
WSAStartup($101,wsd);
s:=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
he:=gethostbyname('www.21cn.com');
if he=nil then
Raise Exception.Create('err');
FillChar(name,sizeof(name),0);
name.sin_family:=AF_INET;
name.sin_port:=htons(80);
name.sin_addr.S_addr:=PDWORD(PDWORD(he.h_addr)^)^;
connect(s,name,sizeof(name));
str:='GET / HTTP/1.1'#13#10'Host: www.21cn.com'#13#10'Connection: Close'#13#10#13#10;
send(s,PChar(str)^,Length(str),0);
while true do
begin
len:=recv(s,buf,sizeof(buf),0);
if len<1 then
break;
SetString(str,buf,len);
data:=data+str;
end;
closesocket(s);
WSACleanup();
ShowMessage(data);
end;