Q&A

  • 다시 질문 cookie 사용법
unit Ucookietest;



interface



uses

Windows, Messages, SysUtils, Classes, HTTPApp;



type

TWebModule1 = class(TWebModule)

procedure WebModule1writecookieAction(Sender: TObject;

Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

procedure WebModule1readcookieAction(Sender: TObject;

Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

procedure WebModule1readcookie1Action(Sender: TObject;

Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

private

{ Private declarations }

public

{ Public declarations }

end;



var

WebModule1: TWebModule1;



implementation



{$R *.DFM}



procedure TWebModule1.WebModule1writecookieAction(Sender: TObject;

Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

var

mycookies:TStringList;

begin

mycookies:=TStringList.Create;

with mycookies do

Begin

Add('Name=Frank Borland');

end;

with Response do

begin

SetCookieField(mycookies,'localhost','/',now+1,false);

content:='Cookies planted';

end;

mycookies.Free;

end;



/---- 이분분에서 값을 얻어오는데...

procedure TWebModule1.WebModule1readcookieAction(Sender: TObject;

Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

begin

Response.content:=''+Request.cookie+'';

end;

//-- 값이 나오지를 않아요

//소스는 제데로 된것 같은데...



이런식으로 코딩을 했는데. 되질 않네요...



2  COMMENTS
  • Profile
    갱수 2000.01.29 02:28
    이곤섭 wrote:

    > unit Ucookietest;

    >

    > interface

    >

    > uses

    > Windows, Messages, SysUtils, Classes, HTTPApp;

    >

    > type

    > TWebModule1 = class(TWebModule)

    > procedure WebModule1writecookieAction(Sender: TObject;

    > Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

    > procedure WebModule1readcookieAction(Sender: TObject;

    > Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

    > procedure WebModule1readcookie1Action(Sender: TObject;

    > Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

    > private

    > { Private declarations }

    > public

    > { Public declarations }

    > end;

    >

    > var

    > WebModule1: TWebModule1;

    >

    > implementation

    >

    > {$R *.DFM}

    >

    > procedure TWebModule1.WebModule1writecookieAction(Sender: TObject;

    > Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

    > var

    > mycookies:TStringList;

    > begin

    > mycookies:=TStringList.Create;

    > with mycookies do

    > Begin

    > Add('Name=Frank Borland');

    > end;

    > with Response do

    > begin

    > SetCookieField(mycookies,'localhost','/',now+1,false);

    > content:='Cookies planted';

    > end;

    > mycookies.Free;

    > end;

    >

    > /---- 이분분에서 값을 얻어오는데...

    > procedure TWebModule1.WebModule1readcookieAction(Sender: TObject;

    > Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

    > begin

    > Response.content:=''+Request.cookie+'';

    > end;

    > //-- 값이 나오지를 않아요

    > //소스는 제데로 된것 같은데...

    >

    > 이런식으로 코딩을 했는데. 되질 않네요...

    >

    안녕하세요^^

    우연하게 뉴스그룹을 보다가 요..

    대충예기는 setcookiefield랑 sendredirect를 같은 action에서 사용을 못한다는 애기네요^^

    그래서 저같은경우도 그랫었나 보네요..

    다아시는건가?^^



    I have tried the exact same thing, and my experience was that the cookie was

    not written to the client when I used the same construction using

    SetCookieField and then sendRedirect.

    I had to return a normal response, and I solved it by filling the

    Response.Content property with a dynamic created html-string containing only

    a header and a metatag. The metatag was something like
    HTTP-EQUIV="REFRESH" CONTENT="0 URL=%s">, where %s was replaced with the url

    to my other dll (with parameters), and the cookiefield was just as before.

    I thought this was a somewhat stupid an inefficient solution, but the

    cookiefield was written to the client, and my other dll could read it and I

    was happy...

    If there are other (and better) solutions out there, please let me know!







  • Profile
    갱수 2000.01.21 05:45
    이곤섭 wrote:

    > unit Ucookietest;

    >

    > interface

    >

    > uses

    > Windows, Messages, SysUtils, Classes, HTTPApp;

    >

    > type

    > TWebModule1 = class(TWebModule)

    > procedure WebModule1writecookieAction(Sender: TObject;

    > Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

    > procedure WebModule1readcookieAction(Sender: TObject;

    > Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

    > procedure WebModule1readcookie1Action(Sender: TObject;

    > Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

    > private

    > { Private declarations }

    > public

    > { Public declarations }

    > end;

    >

    > var

    > WebModule1: TWebModule1;

    >

    > implementation

    >

    > {$R *.DFM}

    >

    > procedure TWebModule1.WebModule1writecookieAction(Sender: TObject;

    > Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

    > var

    > mycookies:TStringList;

    > begin

    > mycookies:=TStringList.Create;

    > with mycookies do

    > Begin

    > Add('Name=Frank Borland');

    > end;

    > with Response do

    > begin

    > SetCookieField(mycookies,'localhost','/',now+1,false);

    > content:='Cookies planted';

    > end;

    > mycookies.Free;

    > end;

    >

    > /---- 이분분에서 값을 얻어오는데...

    > procedure TWebModule1.WebModule1readcookieAction(Sender: TObject;

    > Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

    > begin

    > Response.content:=''+Request.cookie+'';

    > end;

    > //-- 값이 나오지를 않아요

    > //소스는 제데로 된것 같은데...

    >

    > 이런식으로 코딩을 했는데. 되질 않네요...

    >



    안녕하세요^^

    SetCookieField(mycookies,'localhost','/',now+1,false);

    이부분에서 'localhost'를 직접 IP를 적던지 도메인 명을 적어 보세요..

    그럼 시스템 디렉토리및에 NT라면 profile밑에 자신의 디렉토리 밑에 cookie에 text형식으로 저장이 되어있을겁니다. localhost로 하면 쿠키값이 안생기구요^^



    그리고 now+1 보다는 -1 값으로 정해놓으시면 조그이나마 보안쪽으로는