
22.11.2010, 23:58
|
 |
Активный
|
|
Регистрация: 12.09.2008
Сообщения: 275
Репутация: 43
|
|
Код:
function GetCookie(FText: TStringList): String;
var
N, I: Integer;
S: String;
begin
Result := '';
for N := 0 to FText.Count - 1 do
if Pos('set-cookie:', LowerCase(FText[N])) = 1 then
begin
S:= FText[N];
Delete(S, 1, Length('set-cookie: '));
I:= Pos(';', S);
S:= Copy(S, 1, I-1);
if Result <> '' then
Result := Result + '; ';
Result := Result + S;
end;
end;
Код:
procedure TForm1.Button1Click(Sender: TObject);
var
Data: TStringList;
Otvet: String;
S: String;
begin
Otvet:= IdHTTP1.Get('http://parapa.mail.ru/forums/');
IdHTTP1.CookieManager.AddCookie(GetCookie(IdHTTP1.Response.RawHeaders), 'parapa.mail.ru'); // добавляем сокет
IdHTTP1.Request.Referer:= 'http://parapa.mail.ru/forums/';
IdHTTP1.HandleRedirects:= False;
Data:= TStringList.Create;
Data.Add('login='+LabeledEdit1.Text);
if CheckBox1.Checked then
Data.Add('authsave=1');
Data.Add('password='+LabeledEdit2.Text);
try
Otvet:= IdHTTP1.Post('http://parapa.mail.ru/auth/login/', Data);
except
IdHTTP1.Request.Clear;
S:= IdHTTP1.Response.Location;
if Pos('err=', S) <> 0 then
Memo1.Lines.Add('Логин или пароль неверны!')
else
begin
Otvet:= Utf8ToAnsi(IdHTTP1.Get(IdHTTP1.Response.Location));
if Pos('Добро пожаловать', Otvet) <> 0 then
Memo1.Lines.Add('Успешно авторизовались!');
end;
end;
Data.Free;
end;
|