Cookie Demo needed - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html) +--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html) +---- Forum: English (https://www.atozed.com/forums/forum-16.html) +----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html) +----- Thread: Cookie Demo needed (/thread-1041.html) |
Cookie Demo needed - cpstevenc - 04-24-2019 Is there any cookie usage demos? There isn't one in the Github download of demos. Using Tokyo 10.2.1 IW 15.0.20 Stand Alone Server TIWStandAloneServer being used to have a custom server form. AllowMultipleSessionsPerUser = TRUE For our VCL / FMX Mobile App... gotta supply 4 values to login in to the service. Two of them can be restored back from a cookie when you come back to page at a later date/time... the other two values have to be put in. I am not 100% sure the proper usages of WebApplication.Response.Cookies.AddCookie and webapplication.Request.CookieFields.Values of when I should be using these... And for the addCookie, what kind of parameters I should be using for PATH and such as I don't want it tied to a the random generated session path/id. Thanks! - RE: Cookie Demo needed - DanBarclay - 04-24-2019 Here is something from the old forum (forum is now readonly) https://forums.embarcadero.com/thread.jspa?messageID=693421#693421 Also see: https://forums.embarcadero.com/thread.jspa?messageID=882882#882882 From Alex: Reading cookie value: Class THttpRequest, method GetCookieValue: function GetCookieValue(const aName: string): string; Writing a cookie: Class THttpReply, use method AddCookie from Cookies object (type THttpCookieList), e.g.: Reply.Cookies.AddCookie() function AddCookie(const aName, aValue, aPath: string; const aExpires: TDateTime; const aHttpOnly: Boolean = False; const aSecure: Boolean = False): Integer; Also from Alex in the second thread, HTTPOnly... Is there a way to set the HTTPOnly flag in the Set-Cookie HTTP response header? Is this a custom cookie or the default session tracking cookie? If this is the default session tracking cookie, just use the ServerController.CookieOptions property: - set CookieOptions.HttpOnly to True/False, according to your requirements If this is a custom cookie, you can set this option when adding the cookie to the response cookie collection: THttpReply.Cookies is the cookie coolection object. You use its Add() method to add a custom cookie to your response, and this method has this signature: THttpCookieList.AddCookie(const aName, aValue, aPath: string; const aExpires: TDateTime; const aHttpOnly: Boolean = False; const aSecure: Boolean = False): Integer; Dan RE: Cookie Demo needed - cpstevenc - 04-25-2019 I ran into those too.. either calls changed, or missing some information in those original posts. I need cookies that are not locked to the session. So user can come back at a later date and data is there to grab? RE: Cookie Demo needed - DanBarclay - 04-25-2019 (04-25-2019, 05:05 AM)cpstevenc Wrote: I ran into those too.. either calls changed, or missing some information in those original posts. Try this to set your cookie. Code: webapplication.Response.Cookies.Add(THTTPCookie.Create(CookieName,CookieValue,'/',Expireon,true)); Name/Value are String. Try this to read the cookie: Code: Result := webapplication.Request.CookieFields.Values[sName]; It should work, but there may be better ways. Dan RE: Cookie Demo needed - cpstevenc - 05-05-2019 (04-25-2019, 06:14 AM)DanBarclay Wrote:(04-25-2019, 05:05 AM)cpstevenc Wrote: I ran into those too.. either calls changed, or missing some information in those original posts. Thanks! UTCDateTime was my issue. Also used Chrome inspector and took me a bit to find the call that was actually kicking off the COOKIE code to save and saw my date being used was in like 1927 .... so expired |