
23.06.2011, 14:45
|
 |
Let Me Show You
|
|
Регистрация: 30.04.2010
Адрес: Северодвинск
Сообщения: 5,426
Версия Delphi: 7, XE5
Репутация: 59586
|
|
Код:
unit Unit1;
interface
uses
IdHTTP, IdCookieManager,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient;
type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
Button1: TButton;
Button2: TButton;
IdHTTP1: TIdHTTP;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses IdCookie, IdHTTPHeaderInfo, StrUtils;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
AStrings: TStrings;
s: String;
begin
IdHTTP1.AllowCookies:=False;
IdHTTP1.Request.UserAgent:='Mozilla/3.0';
AStrings:=TStringList.Create;
try
AStrings.Add('handle=don.sim2012@yandex.ru');
AStrings.Add('password=123456789');
IdHTTP1.Request.ContentType:='application/x-www-form-urlencoded';
try
IdHTTP1.Post('http://lockerz.com/auth/login', AStrings);
except
Memo2.Lines.Assign(IdHTTP1.Response.RawHeaders);
for i:=0 to IdHTTP1.Response.RawHeaders.Count-1 do
if AnsiStartsText('Set-Cookie: lockerz2=', IdHTTP1.Response.RawHeaders[i]) then
begin
s:=IdHTTP1.Response.RawHeaders[i];
s:=Copy(s, 22, Length(s));
s:=Copy(s, 1, Pos(';', s)-1);
end;
Memo1.Text:=s;
end;
finally
AStrings.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
IdHTTP1.Request.CustomHeaders.Text:='Cookie: lockerz2='+Memo1.Text;
IdHTTP1.Request.ContentType:='';
IdHTTP1.Request.ContentLength:=-1;
Memo1.Text:=IdHTTP1.Get(IdHTTP1.Response.Location);
Memo2.Lines.Assign(IdHTTP1.Response.RawHeaders);
Memo1.Lines.SaveToFile('d:\Downloads\lockerz2.htm');
end;
end.
http://data.cod.ru/112283
в htm будет строчка " Hello, Alexander {My Account} | {Sign Out}", что говорит о работоспособности метода. довести до ума мне лень, основной момент, думаю, понятен.
__________________
Пишу программы за еду.
__________________
|