怎样实现下载一个某一个网页文件?(用delphi7)比如:我想下载www.sina.com.cn\index.html我在网上查的都是用nmftp等控件,但在delphi7里并没有找到这个控件

解决方案 »

  1.   

    用Indy的IdHTTP组件
    NM淘汰的,不要用了http://lysoft.7u7.net
      

  2.   

    网上有的用下面方面:用NMHttp控件.
    var txt:string;
    begin
      nmhttp1.get('http://dailynews.sina.com.cn/world/index.htm');
      txt:=nmhttp1.body;
    end;
    但是在delphi7里没有找到nmhttp1控件,应该用什么去做
      

  3.   

    推荐 《Delphi 7 Web开发与应用》源程序.rar你上网搜索一下,有地方下载的。
      

  4.   

    我在网上找到一段登录CSDN的代码,如下所写,但是执行到下面两句时出错,请问为什么
        IdHTTP1.Request.Referer:='http://www.csdn.net/member/UserLogin.asp';
        IdHTTP1.Request.From :='http://community.csdn.net/Expert/Forum.asp';代码如下:
    function Logon(UserName, PassWord, CookieTime: string):boolean;
    var
      LoginInfo: TStrings;
      Response: TStringStream;
      i: Integer;
      Cookie:string;begin
      Result :=False;
      Cookie:='';
      MyCookList :='';
      Response := TStringStream.Create('');
      LoginInfo := TStringList.Create;
      try
        LoginInfo.Clear;
        LoginInfo.Add('login_name='+UserName);
        LoginInfo.Add('password='+PassWord);
        LoginInfo.Add('from=http://community.csdn.net/Expert/Forum.asp');
        LoginInfo.Add('cookietime='+CookieTime);
        LoginInfo.Add('x=0');
        LoginInfo.Add('y=0');
        IdHTTP1.Request.Referer:='http://www.csdn.net/member/UserLogin.asp';
        IdHTTP1.Request.From :='http://community.csdn.net/Expert/Forum.asp';
        try
          IdHTTP1.Post(LoginUrl,LoginInfo,Response);
        except
          showmessage('登录失败’);
        end;
        showmessage(Response.DataString);
        for i :=0 to IdHTTP1.Response.RawHeaders.Count-1 do
        begin
          if UpperCase(Copy(IdHTTP1.Response.RawHeaders[i],1,10)) = 'SET-COOKIE' then
          begin
            Cookie :=Trim(Copy(IdHTTP1.Response.RawHeaders[i],12,MAXINT));
            Cookie :=Copy(Cookie,1,Pos(';',Cookie));
            MyCookList :=MyCookList+Cookie;
          //  showmessage(Cookie);
          end;
        end;
        IdHTTP1.Request.RawHeaders.Add('Cookie: '+MyCookList);
      finally
        LoginInfo.Free;
        Response.Free;
      end;
      if length(MyCookList)>200  then
        result:=True;
    end;