I'm new in Delphi and also sorry for my bad English.
I'm using Embarcadero Rad Studio Delphi 10.3.
I need to create Site with delphi, so I create new project
"Delphi\web\webserver application\windows\stand-alone GUI application\vcl application"
in WebModuleUnit (visual view), window "structure" I chose brunch of my page and in
windows "Object Inspector" go to page "events" --> I create event in "OnAction" field
Then I switch to code view and in "WMTestPageAction" procedure wrote this code
procedure TWebModule1.WMTestPageAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
tstStr:tstrings;
const
cookieUserName='UserNameXYZ';
begin
Response.Content :=
'<!DOCTYPE html>'+
'<html>'+
'<head>'+
'<title>Test page</title>'+
'</head>'+
'<body>';
tstStr:=TStringList.Create;
Request.Create;
Request.ExtractCookieFields(tstsTr);
Response.Content :=Response.Content+'<div>test output<br>'+
'get cookie name User = '+cookieUserName+' ; Request.Cookie = '+Request.Cookie +'<br>'+
'get cookie name User = '+cookieUserName+' ; inttostr(Request.Cookie.Length) = '+inttostr(Request.Cookie.Length) +'<br>'+
'get cookie name User = '+cookieUserName+' ; Request.ContentFields.Text = '+Request.ContentFields.Text +'<br>'+
'get cookie name User = '+cookieUserName+' ; Request.ContentFields.Values[''UserNameXYZ''] = '+Request.ContentFields.Values['UserNameXYZ'] +'<br>'+
'get cookie name Token= '+cookieUserToken+' ; Request.ContentFields.Values[cookieUserToken] = '+Request.ContentFields.Values[cookieUserToken]+'<br>'+
' Request.Content = '+ Request.Content +'<br>'+
' tstsTr.Text = '+ tstsTr.Text +'<br>'+
'<br>Response<br>'+
' Response.HTTPRequest.Cookie '+ Response.HTTPRequest.Cookie +'<br>'+
' Response.Cookies.Count = '+ IntToStr(Response.Cookies.Count) +'<br>'+
' Response.GetCustomHeader(''name2'') = '+ Response.GetCustomHeader('name2') +'<br>'+
' Response.GetCustomHeader(''name2'') = '+ '' +'<br>'+
'</div>';
Response.Content :=Response.Content+'</body></html>';
end;
in "response" I can form my page and I use this to get test info,
I can set Cookie with Response.SetCookieField(scValues,scDomen,scPath,scExpiries,scSecure);
but I can't get cookie in delphi on loading page, all what I try I wrote in code.
in browser console on command document.cookie
I recive"name2=value2; UserNameXYZ=jack; token=sd78sd78s7d8s"
I want to check user session on each load of all the pages in my site.
Respone and Request in code belongs to module "Web.HTTPApp".
Please advice.
Aucun commentaire:
Enregistrer un commentaire