Delphi TIdHTTP 登录网页封装


本文整理自网络,侵删。

 

uses IdHTTP;

 

function DoLogin(const username, password: string): string;

var

  IdHTTP: TIdHTTP;

  Request: TStringList;

begin

  try

    Request := TStringList.Create;

    try

      Request.Add('action=do_login');

      Request.Add('url=http://www.delphican.com/index.php');

      Request.Add('quick_login=1');

      Request.Add('quick_username='+username);

      Request.Add('quick_password='+password);

      Request.Add('quick_remember=yes');

      Request.Add('submit=Giri? Yap');

      IdHTTP := TIdHTTP.Create;

      try

        IdHTTP.AllowCookies := True;

        IdHTTP.HandleRedirects := True;

        IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';

        IdHTTP.Post('http://www.delphican.com/member.php', Request);

        Result := IdHTTP.Get('http://www.delphican.com');

        if ContainsStr(Result, 'quick_login') then //Login ba?ar?s?z demektir

          Result := '';

      finally

        IdHTTP.Free;

      end;

    finally

      Request.Free;

    end;

  except

    Result := '';

  end;

end;

 

 

 

 

方法2:

uses IdHTTP;

 function baglan(const username, password: string): string;

var

IdHTTP: TIdHTTP;

Request: TStringList;

begin

try

  Request := TStringList.Create;

  try

     Request.Add('work=login');

     Request.Add('login_user='+username);

     Request.Add('login_pass='+password);

    IdHTTP := TIdHTTP.Create;

    try

      IdHTTP.AllowCookies := True;

      IdHTTP.HandleRedirects := True;

      IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';

      IdHTTP.Post('http://deneme/src/api.php', Request);

      Result := IdHTTP.Get('http://deneme');

      if StrUtils.ContainsStr(Result, 'G?R?? YAP') then //Login ba?ar?s?z 

        Result := '' else begin

          Result := IdHTTP.Get('http://deneme/salon.html?id=1');

        end;

    finally

     // IdHTTP.Free;

    end;

  finally

    Request.Free;

  end;

except

  Result := '';

end;

end;

相关阅读 >>

Delphi 用空格把 s 凑够 n 的长度

Delphi xe增强的rtti妙用--动态创建包中的窗口类

Delphi图像细化处理

Delphi inc函数和dec函数的用法

Delphi的几种类型转换

Delphi 去掉twebbrowser的滚动条

Delphi 修改exe应用程序图标

Delphi webbrowser选中文本操作 设置webbrowser的内容

Delphi的流操作的语法

Delphi 在瑞星2010全保护下创建文件夹

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...