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;
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.044185876846313 seconds