Jak wiesz nie miałem poprawnych danych do zalogowania się ale na moje oko coś w tym stylu:
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
System.DateUtils, System.RegularExpressions, Vcl.Graphics, Vcl.Controls, Vcl.Forms,
Vcl.Dialogs, Vcl.StdCtrls,
IdZLibCompressorBase,IdCompressorZLib, IdIOHandler, IdIOHandlerSocket,
IdIOHandlerStack, IdSSL,IdSSLOpenSSL, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
IdHTTP1: TIdHTTP;
IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
IdCompressorZLib1: TIdCompressorZLib;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function GetUNIXTimeInMilliseconds: Int64;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.GetUNIXTimeInMilliseconds: Int64;
var
DateTime: TDateTime;
SystemTime: TSystemTime;
begin
GetSystemTime(SystemTime);
DateTime:= System.SysUtils.EncodeDate(SystemTime.wYear, SystemTime.wMonth, SystemTime.wDay) +
System.SysUtils.EncodeTime(SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond, SystemTime.wMilliseconds);
result:= System.DateUtils.MilliSecondsBetween(DateTime, UnixDateDelta);
end;
procedure TForm1.Button1Click(Sender: TObject);
const
HOST = 'https://*********'; //domena bez / na końcu
USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0';
CONTENT_TYPE = 'application/x-www-form-urlencoded; charset=UTF-8';
LOGIN_PAGE_URL_FRMT = '%0:s/administrace/ajax-tab.php?rand=%1:d';
//%0:s - hasło
//%1:s - email
//%0:s - token
LOGIN_POST_DATA_FRMT = 'ajax=1&controller=AdminLogin&submitLogin=1&passwd=%0:s&email=%1:s&redirect=&%2:s';
var
sLoginURL: string;
sHTML: string;
sToken: string;
sPostData: string;
regex: TRegEx;
match: TMatch;
ss: TStringStream;
begin
IdHTTP1.IOHandler:= IdSSLIOHandlerSocketOpenSSL1;
IdHTTP1.Compressor:= IdCompressorZLib1;
IdHTTP1.HandleRedirects:= True;
IdHTTP1.Request.UserAgent:= USER_AGENT;
IdHTTP1.Request.ContentType:= CONTENT_TYPE;
sLoginURL:= Format(LOGIN_PAGE_URL_FRMT, [HOST, GetUNIXTimeInMilliseconds()]);
sHTML:= IdHTTP1.Get(sLoginURL);
regex:= TRegEx.Create('token=(.+?)"');
match:= regex.Match(sHTML);
if match.Success then //udalo sie pobrac token
begin
sToken:= match.Value;
sPostData:= Format(LOGIN_POST_DATA_FRMT, ['HASLO', 'ADRES@EMAIL', sToken]);
ss:= TStringStream.Create(sPostData);
ss.Position:= 0;
sHTML:= IdHTTP1.Post(sLoginURL, ss);
Memo1.Lines.Add(sHTML); //tu powinieneś mieć chyba JSON z info o powodzeniu lub nie logowania
end;
end;
Oczywiście logowanie z użyciem SSL wiec pamiętaj o dodaniu wymaganych przez Indy bibliotek do folderu z programem.