idhttp获取网页源文件出错,急求解决办法!
以下程序中,button1.click获取代码出错,button2.click则正常.不知是网站的原因还是什么?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
Button1: TButton;
IdHTTP1: TIdHTTP;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.Text:=idhttp1.Get('http://www.zhcw.com/data-js/nowdata98.js');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
memo2.Text:=idhttp1.Get('http://result.lottery.gov.cn/qxcpl3.js');
end;
end.
[解决办法]
再这次试一下,看看怎么样。
procedure TForm1.Button2Click(Sender: TObject);
var
myidhttp1:Tidhttp;
begin
myIDHttp1:=Tidhttp.Create(nil);
myIDHttp1.request.UserAgent:= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; MyIE2; CustomExchangeBrowser; .NET CLR 1.1.4322) ';
memo2.Text:=myIDHttp1.Get( 'http://result.lottery.gov.cn/qxcpl3.js ');
end;
end.