unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, WinInet, StdCtrls, Buttons;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
BitBtn1: TBitBtn;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
sSaved, sGet:
String;
const
cKeyCode:
String = '
148576298388';
implementation
{$R *.dfm}
uses RC4;
//Funktion zum stzen des Cookies
//Funktioniert einwandfrei
//Cookie wird auf Festplatte geschrieben und bleibt auch
procedure SetCookie(sValue:
String);
var
bReturn: Boolean;
pCookiename, pURL, pValue: PAnsiChar;
sTemp:
String;
begin
pCookiename := PAnsiChar('
TestData');
pURL := PAnsiChar('
http://localhost');
sValue := RC4Code(sValue, cKeyCode);
sSaved := sValue;
{ //Vergleich alls String und Ansi, kein Unterschied
sTemp := 'Normal value: ' + sValue;
sTemp := sTemp + ' Pansi value: ' + PAnsiChar(sValue);
ShowMessage(sTemp);
}
pValue := PAnsiChar(sValue + '
; expires = Sat, 01-Jan-2007 00:00:00 GMT');
bReturn := InternetSetCookie(pURL, pCookiename, pValue);
if(
not bReturn)
then ShowMessage('
FALSE SetCookie');
end;
function GetCookie:
String;
var
pURL, pName: PAnsiChar;
pData: AnsiString;
cSize, cError: Cardinal;
bResult: Boolean;
sString2, sString:
String;
iPos, iX: Integer;
begin
pURL := PAnsiChar('
http://localhost');
pName := PAnsiChar('
TestData');
cSize := 255;
pData := '
';
bResult := FALSE;
//ShowMessage('1 try');
try
InternetGetCookie(pURL, pName,
nil, cSize);
except
on E:
Exception do begin
cError := Windows.GetLastError();
if(cError = ERROR_NO_MORE_ITEMS)
then begin
ShowMessage('
ERROR_NO_MORE_ITEMS');
end;
if(cError = ERROR_INSUFFICIENT_BUFFER)
then begin
ShowMessage('
ERROR_INSUFFICIENT_BUFFER');
end;
ShowMessage(E.
Message+'
'+IntToStr(E.HelpContext));
exit;
end;
end;
pURL := PAnsiChar('
http://localhost');
pName := PAnsiChar('
TestData');
SetLength(pData, cSize);
//ShowMessage('2 try');
try
bResult := InternetGetCookie(pUrl, pName, PAnsiChar(pData), cSize);
except
on E:
Exception do begin
cError := Windows.GetLastError();
if(cError = ERROR_NO_MORE_ITEMS)
then begin
ShowMessage('
ERROR_NO_MORE_ITEMS');
end;
if(cError = ERROR_INSUFFICIENT_BUFFER)
then begin
ShowMessage('
ERROR_INSUFFICIENT_BUFFER');
end;
ShowMessage(E.
Message+'
'+IntToStr(E.HelpContext));
exit;
end;
end;
if(bResult = FALSE)
then begin
ShowMessage('
GET COOKIE FALSE');
exit;
end;
if(bResult = TRUE)
then begin
ShowMessage('
PAnsi Data: ' + pData);
//Daten werden verändert gelesen
SetLength(sString, Length(pData));
sString := pData;
iPos := 0;
for iX := 0
to Length(sString)
do begin
if(sString[iX] = '
=')
then begin
iPos := iX;
break;
end;
end;
if(iPos <> 0)
then begin
SetLength(sString2, (Length(sString) - iPos));
//Alternativ benutze ich hier auch (Length(sString))-1
sString2 := Copy(sString, (iPos+1), (Length(sString)));
ShowMessage('
sString2: ' + sString2);
sString2 := RC4Code(sString2, cKeyCode);
sGet := sString;
end;
ShowMessage('
GET COOKIE TRUE - Cookie: ' + sString2);
Result := pData;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SetCookie('
doof22_dumm11');
end;
procedure TForm1.Button2Click(Sender: TObject);
var
sString:
String;
begin
sString := '
';
sString := GetCookie;
ShowMessage('
Compare - Saved: ' + sSaved + '
to: ' + sGet);
end;
end.