E
E
Evgeny Ivanov2016-12-14 10:33:34
Delphi
Evgeny Ivanov, 2016-12-14 10:33:34

How to send a request over https from an authorized user?

There is a site that works on the https protocol. You need to get the content of the page of this site as an authorized user.

The site code responsible for the authorization procedure is known.

<form id="fm1" class="fm-v clearfix" action="/cas/login?..............
<input id="username" name="username".............
<input id="password" name="password"................
<input type="hidden" name="lt" value="LT-119266-9dAAvjJj9JJAMhjCf2cHVScDuKi4Fj" />
<input type="hidden" name="execution" value="e1s1" />
<input type="hidden" name="_eventId" value="login"/>

Site address known rmisssite.ru/cas/login
Libraries added to Delphi 7 project.

The procedure below gets the content of the page as a normal user. Everything is working.
Shows page code as not authorized user.
procedure get_https_file_content_to_memo(https_url:string);
var
IdHTTP1: TIdHTTP;
IdSSLIOHandlerSocket1: TIdSSLIOHandlerSocket;
server_response:string;
text_file: textfile;
begin
//Кодируем url- ведь бывает url с параметрами, где есть кириллица
https_url:=AnsiToUtf8(https_url);
https_url:=TIdURI.URLEncode(https_url);
 
IdHTTP1:=TIdHTTP.Create(nil);
IdHTTP1.HandleRedirects:=true;
IdHTTP1.RedirectMaximum:=15;
 
IdSSLIOHandlerSocket1:=TIdSSLIOHandlerSocket.Create(IdHTTP1);
IdSSLIOHandlerSocket1.SSLOptions.Method := sslvTLSv1;
IdHTTP1.IOHandler:=IdSSLIOHandlerSocket1;
server_response:=utf8toansi(IdHTTP1.Get(https_url));
IdSSLIOHandlerSocket1.Destroy;
IdHTTP1.Destroy;
//Выводим ответ в поле мемо
form1.memo1.Lines.Add(server_response);
end;


The procedure below should log in and request the page code - already as an authorized user. written based on the procedure above. But it does not work as it should - it displays the code of the authorization page. Those. authorization failed and we were returned to entering a login and password.
procedure TForm1.Button2Click(Sender: TObject);
var
IdHTTP1: TIdHTTP;
IdSSLIOHandlerSocket1: TIdSSLIOHandlerSocket;
server_response,https_url:string;
params:tstringlist;
CM:TidCookieManager;
begin
form1.Memo1.Clear;

//Лист наших параметров - что будем передавать сайту
params:=TStringList.Create;
params.Add('username=petrov_aa');
params.Add('password=1234567');
params.Add('execution=e1s1');
params.Add('_eventId=login');
params.Add('lt=LT-122030-HXG4k4TRkxqPDfgTr2iALl'); //Параметр постоянно меняется (

//Адрес сайта - куда будем передавать
https_url:='https://rmisssite.ru/cas/login';

//Создание и настройка соединения
https_url:=AnsiToUtf8(https_url);
https_url:=TIdURI.URLEncode(https_url);
IdHTTP1:=TIdHTTP.Create(nil);
IdHTTP1.HandleRedirects:=true;
IdHTTP1.RedirectMaximum:=15;

//В интернете пишут, что нужно хранить куки
CM := TidCookieManager.Create(IdHTTP1);
IdHTTP1.AllowCookies := true;
IdHTTP1.CookieManager := CM;

IdSSLIOHandlerSocket1:=TIdSSLIOHandlerSocket.Create(IdHTTP1);
IdSSLIOHandlerSocket1.SSLOptions.Method := sslvTLSv1;
IdHTTP1.IOHandler:=IdSSLIOHandlerSocket1;

//Авторизация
server_response:=utf8toansi(IdHTTP1.Post(https_url,params));
//Мы ведь авторизированы? Теперь нужно получить содержимое "закрытой" страницы
server_response:=utf8toansi(IdHTTP1.Get('https://rmisssite.ru/edit/363'));
//server_response:=utf8toansi(IdHTTP1.Post('https://rmisssite.ru/edit/363',params)); А может так надо??

//Все сделано - уничтожаем объекты
IdSSLIOHandlerSocket1.Destroy;
IdHTTP1.Destroy;
params.free;

//Код страницы выводим в мемо
form1.memo1.Lines.Add(server_response);

end;


How to send a request over https from an authorized user? What errors do you see in the procedure above?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question