以下程序中,button1.click获取代码出错,button2.click则正常.不知是网站的原因还是什么?unit Unit1;interfaceuses
  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.

解决方案 »

  1.   

    把错误代码贴上啊,我最近也在用idhttp
      

  2.   

    看看网张是否对浏览器做了限制了,因为idhttp默认的是Mozilla/3.0,如果是的话,修改useragent
      

  3.   

    请教如何改?只是近期才出现这个问题的.虽然我已经采用先下载再分析的办法解决,但始终比直接get要慢点.网站可以对浏览器做限制的?那它岂不是失去很多用户?
      

  4.   

    再这次试一下,看看怎么样。
    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.