unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdCookie, IdIntercept, IdLogBase, IdLogEvent, StdCtrls,
IdCookieManager, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StrUtils, ExtCtrls,
ActiveX,
Vcl.OleCtrls, SHDocVw;
type
TfrmMain =
class(TForm)
IdHTTP: TIdHTTP;
IdCookieManager: TIdCookieManager;
memLog: TMemo;
IdLogEvent: TIdLogEvent;
pnlMain: TPanel;
btnLogin: TButton;
btnLogout: TButton;
lblEmail: TLabel;
edtEmail: TEdit;
lblPassword: TLabel;
edtPassword: TEdit;
WebBrowser1: TWebBrowser;
Memo1: TMemo;
Edit1: TEdit;
Button1: TButton;
procedure IdHTTPRedirect(Sender: TObject;
var dest:
string;
var NumRedirect: Integer;
var Handled: Boolean;
var VMethod: TIdHTTPMethod);
procedure btnLogoutClick(Sender: TObject);
procedure btnLoginClick(Sender: TObject);
procedure IdLogEventSent(ASender: TComponent;
const AText, AData:
string);
procedure IdLogEventReceived(ASender: TComponent;
const AText, AData:
string);
procedure IdCookieManagerNewCookie(ASender: TObject; ACookie: TIdCookie;
var VAccept: Boolean);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure WB_LoadHTML(WebBrowser: TWebBrowser; HTMLCode:
string);
var
sl: TStringList;
ms: TMemoryStream;
begin
WebBrowser.Navigate('
about:blank');
while WebBrowser.ReadyState < READYSTATE_INTERACTIVE
do
Application.ProcessMessages;
if Assigned(WebBrowser.Document)
then
begin
sl := TStringList.Create;
try
ms := TMemoryStream.Create;
try
sl.Text := HTMLCode;
sl.SaveToStream(ms);
ms.Seek(0, 0);
(WebBrowser.Document
as IPersistStreamInit).Load(TStreamAdapter.Create(ms));
finally
ms.Free;
end;
finally
sl.Free;
end;
end;
end;
procedure TfrmMain.btnLoginClick(Sender: TObject);
var
sHTMLCode, sURL, strQuelltext :
String;
iPos1, iPos2: Integer;
sFormKey, sIV, sCheckCode:
String;
slParams: TStringList;
begin
slParams := TStringList.Create;
slParams.Add('
loginname='+edtEmail.Text);
slParams.Add('
password='+edtPassword.Text);
strQuelltext := IdHTTP.Post('
http://lounge.deutschlandsim.de/login', slParams);
slParams.Free;
WB_LoadHTML(WebBrowser1, strQuelltext);
end;
procedure TfrmMain.btnLogoutClick(Sender: TObject);
begin
IdHTTP.Get('
http://lounge.deutschlandsim.de/logout');
end;
procedure TfrmMain.Button1Click(Sender: TObject);
begin
Webbrowser1.Navigate(Edit1.Text);
end;
procedure TfrmMain.IdCookieManagerNewCookie(ASender: TObject;
ACookie: TIdCookie;
var VAccept: Boolean);
begin
if (ACookie.Path = '
')
then ACookie.Path :='
/';
memLog.Lines.Add('
New Cookie:');
//memLog.Lines.Add(' Comment: '+ACookie.comment);
//memLog.Lines.Add(' Version: '+ACookie.Version);
memLog.Lines.Add('
CookieText: '+ACookie.CookieText);
memLog.Lines.Add('
ServerCookie: '+ACookie.ServerCookie);
memLog.Lines.Add('
ClientCookie: '+ACookie.ClientCookie);
memLog.Lines.Add('
Domain: '+ACookie.Domain);
memLog.Lines.Add('
Expires: '+DateToStr(ACookie.Expires));
memLog.Lines.Add('
CookieName: '+ACookie.CookieName);
memLog.Lines.Add('
Path: '+ACookie.Path);
memLog.Lines.Add('
Value: '+ACookie.Value);
memLog.Lines.Add('
DisplayName: '+ACookie.DisplayName);
memLog.Lines.Add('
');
end;
procedure TfrmMain.IdHTTPRedirect(Sender: TObject;
var dest:
string;
var NumRedirect: Integer;
var Handled: Boolean;
var VMethod: TIdHTTPMethod);
begin
if (VMethod = Id_HTTPMethodPost)
then VMethod := Id_HTTPMethodGet;
memLog.Lines.Add('
Redirect:');
memLog.Lines.Add('
Dest: '+dest);
memLog.Lines.Add('
NumRedirect: '+IntToStr(NumRedirect));
memLog.Lines.Add('
Handled: '+IntToStr(Integer(Handled)));
memLog.Lines.Add('
Method: '+IntToStr(Integer(VMethod)));
memLog.Lines.Add('
');
end;
procedure TfrmMain.IdLogEventReceived(ASender: TComponent;
const AText, AData:
string);
begin
memLog.Lines.Add('
Received:');
memLog.Lines.Add(AData);
memLog.Lines.Add('
');
end;
procedure TfrmMain.IdLogEventSent(ASender: TComponent;
const AText, AData:
string);
begin
memLog.Lines.Add('
Sent:');
memLog.Lines.Add(AData);
memLog.Lines.Add('
');
end;
end.