procedure TForm1.Timer1Timer(Sender: TObject);
begin
try
label1.caption:=idhttp1.get('http://220.163.15.82/1.txt');
//我想取网上TXT文本的内容来显示,每分钟都取一次,但有时候会意外出错。出了错后就在也取不到内容了,只有把程序关了重新打开才可以。各位大哥,应该怎么做才对。谢谢
except
end;
end;

解决方案 »

  1.   

    1.txt是文件,label1.caption是字符,这样也可以?
    运行能成功?
      

  2.   

    我也遇到过和你一样的问题,
    因为idhttp.get好像没有返回值所以无法判断是否成功.
    后来我用api urldownloadtofile来解决.
    效果一样的.
      

  3.   

    用流文件下载
    ///////////////////////////////
    procedure TUpdate.HttpDownLoad(aURL, aFile: string);
    //aURL  要下载的文件(如http://220.163.15.82/1.txt)
    //aFile 下载保存后的文件(如1.txt)
    var
      tstream: TFileStream;
    begin
      if fileexists(aFile) then tstream := tFilestream.Create(aFile, fmopenwrite)
      else
        tstream := tfilestream.Create(aFile, fmcreate);
      try
        idhttp1.Request.ContentRangeStart := 0;
        try
          idhttp1.Get(aURL, tstream);
        except
          on e: EXCEPTION do
          begin
            application.MessageBox('error', '系统提示', MB_Ok + MB_ICONERROR);
            raise;
          end;
        end;
      finally
        if tstream <> nil then tstream.Free;
      end;
    end;
      

  4.   

    木JJ 倒分嫌疑 呵呵 cccbbbz_cn(狼的智慧)