Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Getting and setting cookies in Tokyo 10.2 and IW14+ C++ Builder


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Oct 2, 2017 7:20 AM Last Post By: Chad Hower Threads: [ Previous | Next ]
charles leggette

Posts: 43
Registered: 7/17/00
Getting and setting cookies in Tokyo 10.2 and IW14+ C++ Builder  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 28, 2017 8:17 AM
In IW12, I had to get someone to write cookies.pas to do this....

Code is below.

Is this necessary now? Hopefully getting/setting cookies in C++ in Tokyo and IW14 is now easy...any comments/example would be greatly appreciated.

unit cookies;

interface

uses
IW.HTTP.Cookie,iwinit,windows,sysutils;

function GetCookieValue(sName: String): String;

//CookieValues array of Name=Value
//ExpireIn - Howmany days
procedure SetCookie(CookieName,CookieValue:String; ExpireIn: Real);// expirein=0 -> session cookie

implementation

function GetUTCDateTime: TDateTime;
var
GMTST: Windows.TSystemTime;
begin
windows.GetSystemTime(GMTST);
result:=Sysutils.SystemTimeToDateTime(GMTST);
end;

function GetCookieValue(sName: String): String;
begin
Result := webapplication.Request.CookieFields.Values[sName];
end;

procedure SetCookie(CookieName,CookieValue:String; ExpireIn: Real);// expirein=0 -> delete when browser closes
var
ExpireOn : real;
begin
if ExpireIn <> 0 then
ExpireOn := GetUTCDateTime + ExpireIn
else
ExpireOn:=-1; // session cookie
webapplication.Response.Cookies.Add(THTTPCookie.Create(CookieName,CookieValue,'/',Expireon));
end;
end.
Chad Hower

Posts: 536
Registered: 3/2/07
Re: Getting and setting cookies in Tokyo 10.2 and IW14+ C++ Builder  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 2, 2017 7:20 AM   in response to: charles leggette in response to: charles leggette
On 9/28/2017 11:17 AM, charles leggette wrote:
In IW12, I had to get someone to write cookies.pas to do this....

Code is below.

Is this necessary now? Hopefully getting/setting cookies in C++ in Tokyo and IW14 is now easy...any comments/example would be greatly appreciated.

No easy? Cookie code is pretty simple and the code you have shown
amounts to only 5 lines of uncompacted code? Am I missing something?
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02