Z
ZhuXiaoTong
Unregistered / Unconfirmed
GUEST, unregistred user!
我想设计一Web程序,使用Cookie传递客户端信息,
但总不成功,具体情况如下:
系统环境:
Windows NT Server 4.0独立服务器
IIS4.0 新建一虚拟目录WWW指向程序所在目录
建立一CGI程序,加入两个Action:Set和Disp,Path与名同
代码如下:
procedure TWebModule1.WebModule1SetAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
MyCook:TStringList;
begin
MyCook:=TStringList.Create ;
try
MyCook.Add('items1 = aaa');
MyCook.Add('items2 = bbb');
response.SetCookieField(MyCook,'Localhost','/',Now+1,False);
Response.content:='Set Ok';
finally
MyCook.free;
end;
end;
procedure TWebModule1.WebModule1DispAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
s:string;
i:integer;
begin
s:='<P>'+'All:'+Request.Cookie +'</p>'+#13 ;
s:=s+'<p>'+'Count:'+inttostr(Request.ContentFields.Count)+'</p>'+#13;
s:=s+'Detail:'+#13;
for i:=0 to Request.ContentFields.Count -1 do begin
s:=s+Request.CookieFields.Names+':'+Request.CookieFields.Values[Request.ContentFields.Names]+#13;
end;
Response.content:=s;
end;
编译生成NewCook.exe,在本机上测试:
浏览器上输入:http://localhost/www/NewCook.exe/Set
结果显示:Set Ok
输入:http://localhost/www/NewCook.exe/Disp取不到所写数据,只显示:
All:
Count:0
Detail:
请问是什么原因,是否与机器配置有关系?如果使用Session对象,该如何进行?
但总不成功,具体情况如下:
系统环境:
Windows NT Server 4.0独立服务器
IIS4.0 新建一虚拟目录WWW指向程序所在目录
建立一CGI程序,加入两个Action:Set和Disp,Path与名同
代码如下:
procedure TWebModule1.WebModule1SetAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
MyCook:TStringList;
begin
MyCook:=TStringList.Create ;
try
MyCook.Add('items1 = aaa');
MyCook.Add('items2 = bbb');
response.SetCookieField(MyCook,'Localhost','/',Now+1,False);
Response.content:='Set Ok';
finally
MyCook.free;
end;
end;
procedure TWebModule1.WebModule1DispAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
s:string;
i:integer;
begin
s:='<P>'+'All:'+Request.Cookie +'</p>'+#13 ;
s:=s+'<p>'+'Count:'+inttostr(Request.ContentFields.Count)+'</p>'+#13;
s:=s+'Detail:'+#13;
for i:=0 to Request.ContentFields.Count -1 do begin
s:=s+Request.CookieFields.Names+':'+Request.CookieFields.Values[Request.ContentFields.Names]+#13;
end;
Response.content:=s;
end;
编译生成NewCook.exe,在本机上测试:
浏览器上输入:http://localhost/www/NewCook.exe/Set
结果显示:Set Ok
输入:http://localhost/www/NewCook.exe/Disp取不到所写数据,只显示:
All:
Count:0
Detail:
请问是什么原因,是否与机器配置有关系?如果使用Session对象,该如何进行?