求取网页源代码的方法,InternetReadFile 除外? 用 InternetReadFile 方法取网页源码有时会失效,有没有其他api稳定性好的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 符合我的要求,WinSock2单元引用的是哪个控件? 改成WinSock也行:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, WinSock; type TForm1 = class(TForm) procedure FormClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormClick(Sender: TObject);var wVersionRequested: WORD; wsaData: TWSAData; sktClient: TSocket; sa: TSockAddr; sHttpHead: array [0..1023] of Char; iReturn: Integer; buf: array [0..1023] of Char; s: string;begin wVersionRequested := MakeWord(2, 0); if 0 <> WSAStartup(wVersionRequested, wsaData) then Exit; sktClient := socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if INVALID_SOCKET = sktClient then Exit; FillChar(sa, SizeOf(TSockAddr), 0); sa.sin_family := AF_INET; sa.sin_port := htons(80); sa.sin_addr.S_addr := inet_addr('202.108.22.5'); if SOCKET_ERROR = connect(sktClient, sa, sizeof(TSockAddr)) then Exit;//showmessage('aa'); sHttpHead := 'GET / HTTP/1.1' + #13 + #10 + //'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*' + #13 + #10 + //'Accept-Language: zh-cn' + #13 + #10 + //'Accept-Encoding: gzip, deflate' + #13 + #10 + //'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)' + #13 + #10 + 'Host: www.baidu.com' + #13 + #10 + 'Connection: Close' + #13 + #10 + #13 + #10; if SOCKET_ERROR = send(sktClient, sHttpHead, strlen(sHttpHead), 0) then Exit; s := ''; repeat ZeroMemory(@buf, 1024); iReturn := recv(sktClient, buf, 1024, 0); s := s + StrPas(buf) + #13 + #10; until (iReturn <= 0) or (iReturn = SOCKET_ERROR); ShowMessage(s); closesocket(sktClient); WSACleanUp();end; end. 还是推荐用Indy取源码,简单多了,呵呵!自己写socket有点麻烦! FastReport如何用代码指定纸张? to 高手救命----关于乱码问题 zdcnow(磁效应) ( ) 信誉:105 谢分贴 大家都是用什么dbgrid控件? 如何用Delphi编程批量修改一个目录下的文件的后缀名 简单问题:如何获取某一个组件所在窗口的名称?50分立送! 如何把excel单元格的属性修改为文本类型 谁能提供一个DVD文件(.vob或.mpg)下载地址? 如何将Word与Excel中的文字属性提取出来? delphi里有没有做*.hlp文件的东东? 请教各位大虾一个问题 关于高度变化
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, WinSock;
type
TForm1 = class(TForm)
procedure FormClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormClick(Sender: TObject);
var
wVersionRequested: WORD;
wsaData: TWSAData;
sktClient: TSocket;
sa: TSockAddr;
sHttpHead: array [0..1023] of Char;
iReturn: Integer;
buf: array [0..1023] of Char;
s: string;
begin
wVersionRequested := MakeWord(2, 0);
if 0 <> WSAStartup(wVersionRequested, wsaData) then Exit;
sktClient := socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if INVALID_SOCKET = sktClient then Exit; FillChar(sa, SizeOf(TSockAddr), 0);
sa.sin_family := AF_INET;
sa.sin_port := htons(80);
sa.sin_addr.S_addr := inet_addr('202.108.22.5');
if SOCKET_ERROR = connect(sktClient, sa, sizeof(TSockAddr)) then Exit;//showmessage('aa'); sHttpHead :=
'GET / HTTP/1.1' + #13 + #10 +
//'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*' + #13 + #10 +
//'Accept-Language: zh-cn' + #13 + #10 +
//'Accept-Encoding: gzip, deflate' + #13 + #10 +
//'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)' + #13 + #10 +
'Host: www.baidu.com' + #13 + #10 +
'Connection: Close' + #13 + #10 + #13 + #10; if SOCKET_ERROR = send(sktClient, sHttpHead, strlen(sHttpHead), 0) then Exit; s := '';
repeat
ZeroMemory(@buf, 1024);
iReturn := recv(sktClient, buf, 1024, 0);
s := s + StrPas(buf) + #13 + #10;
until (iReturn <= 0) or (iReturn = SOCKET_ERROR);
ShowMessage(s);
closesocket(sktClient);
WSACleanUp();
end;
end.