本文整理自网络,侵删。
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 xe增强的rtti妙用--动态创建包中的窗口类
Delphi webbrowser选中文本操作 设置webbrowser的内容
更多相关阅读请进入《Delphi》频道 >>