I have a program in Borland Delphi 7 that uses Indy components and I want to check that my login and password are correct.
This is my current code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack,
IdSSL, IdSSLOpenSSL, IdCookieManager, StrUtils;
type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Button1: TButton;
Memo1: TMemo;
IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
IdCookieManager1: TIdCookieManager;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
post: TStringList;
poczatek, koniec: integer;
aStream: TMemoryStream;
HTML, authToken: string;
fLogin, fHaslo: string;
begin
IdHTTP1.HandleRedirects := True;
fLogin := Edit1.Text;
fHaslo := Edit2.Text;
HTML := IdHTTP1.Get('https://e-skok.pl/eskok/login.jsp');
poczatek := Pos('name="atlassian-token" value="', HTML) +
Length('name="atl_token" value="');
koniec := PosEx('"', HTML, poczatek);
authToken := copy(HTML, poczatek, koniec - poczatek);
post := TStringList.Create;
try
post.Add('atlassian-token=' + authToken);
post.Add('os_username=' + fLogin);
post.Add('os_password=' + fHaslo);
try
IdHTTP1.Request.ContentType:= 'application/json';
HTML:= IdHTTP1.Post('https://e-skok.pl/eskok/login.jsp', post);
Memo1.Text:= HTML;
Label1.Caption := 'YES';
except
if IdHTTP1.ResponseCode = 401 then
begin
ShowMessage('Nieprawidłowy login lub hasło.');
Label1.Caption := 'NO';
end
else
Label1.Caption := ':)';
end;
finally
post.Free;
end;
end;
end.
The problem is when I try to log in, the program always says "Yes" (which mean it's connected, even though login and/or password are wrong).
What is the proper way to check connection with a jsp site via IdHTTP?