Тема: Indy+Redirect
Показать сообщение отдельно
  #7  
Старый 14.06.2011, 15:51
Аватар для NumLock
NumLock NumLock вне форума
Let Me Show You
 
Регистрация: 30.04.2010
Адрес: Северодвинск
Сообщения: 5,426
Версия Delphi: 7, XE5
Репутация: 59586
По умолчанию

Код:
var
  AStrings: TStrings;
  AIdHTTP: TIdHTTP;
  AIdCookieManager: TIdCookieManager;
  StrPage: String;
begin
  AIdHTTP:=TIdHTTP.Create(Self);
  AIdCookieManager:=TIdCookieManager.Create(Self);
  AStrings:=TStringList.Create;

  AIdHTTP.CookieManager:=AIdCookieManager;
  AIdHTTP.AllowCookies:=True;
  AIdHTTP.HandleRedirects:=False;
  AIdHTTP.Host:='www.heroeswm.ru';
  AIdHTTP.Request.Referer:='http://www.heroeswm.ru/';

  try
    AStrings.Add('LOGIN_redirect=1');
    AStrings.Add('login=********');
    AStrings.Add('lreseted=1');
    AStrings.Add('pass=********');
    AStrings.Add('preseted=1');
    AIdHTTP.Request.ContentType:='application/x-www-form-urlencoded';
    try
      AIdHTTP.Post('/login.php', AStrings);
    except
      if (AIdHTTP.ResponseCode div 100)=3 then
      begin
        ACookie:=AIdCookieManager.CookieCollection.Items[0].CookieName+'='+AIdCookieManager.CookieCollection.Items[0].Value+'; ';
        ACookie:=ACookie+AIdCookieManager.CookieCollection.Items[1].CookieName+'='+AIdCookieManager.CookieCollection.Items[1].Value+'; ';
        ACookie:=ACookie+AIdCookieManager.CookieCollection.Items[2].CookieName+'='+AIdCookieManager.CookieCollection.Items[2].Value;

        AIdHTTP.AllowCookies:=False;
        AIdHTTP.CookieManager:=nil;

        AIdHTTP.Request.CustomHeaders.Text:='Cookie: '+ACookie;
        AIdHTTP.Request.ContentType:='';
        AIdHTTP.Request.ContentLength:=-1;
        StrPage:=AIdHTTP.Get('/home.php');
        if Pos('<a href="logout', StrPage)>0 then ShowMessage('Ok');
      end;
    end;
  finally
    AStrings.Free;
    AIdCookieManager.Free;
    AIdHTTP.Free;
  end;
end;
__________________
Пишу программы за еду.
__________________
Ответить с цитированием