
flex中怎么获取cookie
展开全部
<%@ Page Language="C#" EnableEventValidation="false" ResponseEncoding="utf-8"%>
<% //读取Cookie
HttpCookieCollection cookieColl = Request.Cookies;
//获取其中名为VisitorCount的Cookie
HttpCookie oCookie = cookieColl["VisitorCount"];
//检查该Cookie是否存在,如果不存在就新建一个
//也就是第一次访问
if (oCookie == null)
{
HttpCookie newCookie = new HttpCookie("VisitorCount", "1");
newCookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(newCookie);
}
else
{
//如果存在就更新
oCookie.Value = "" + (Convert.ToInt32(oCookie.Value) + 1);
Response.Cookies.Set(oCookie);
}
//返回更新后的值给FLEX
Response.Write(cookieColl["VisitorCount"].Value);
%>
以下为FLEX4.5的代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="send.send()">
<fx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
[Bindable]
var a:String; //动态更新访问次数.会出现警告,但不影响功能,咱不理会!
protected function send_resultHandler(event:ResultEvent):void
{
// TODO Auto-generated method stub
a=event.result.toString();
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<s:HTTPService id="send" url="http://localhost/cookie.aspx" resultFormat="object" result="send_resultHandler(event)"
method="GET" contentType="application/x-www-form-urlencoded">
</s:HTTPService>
</fx:Declarations>
<s:Label x="204" y="182" text="欢迎您第{a}访问本站"/>
</s:Application>
<% //读取Cookie
HttpCookieCollection cookieColl = Request.Cookies;
//获取其中名为VisitorCount的Cookie
HttpCookie oCookie = cookieColl["VisitorCount"];
//检查该Cookie是否存在,如果不存在就新建一个
//也就是第一次访问
if (oCookie == null)
{
HttpCookie newCookie = new HttpCookie("VisitorCount", "1");
newCookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(newCookie);
}
else
{
//如果存在就更新
oCookie.Value = "" + (Convert.ToInt32(oCookie.Value) + 1);
Response.Cookies.Set(oCookie);
}
//返回更新后的值给FLEX
Response.Write(cookieColl["VisitorCount"].Value);
%>
以下为FLEX4.5的代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="send.send()">
<fx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
[Bindable]
var a:String; //动态更新访问次数.会出现警告,但不影响功能,咱不理会!
protected function send_resultHandler(event:ResultEvent):void
{
// TODO Auto-generated method stub
a=event.result.toString();
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<s:HTTPService id="send" url="http://localhost/cookie.aspx" resultFormat="object" result="send_resultHandler(event)"
method="GET" contentType="application/x-www-form-urlencoded">
</s:HTTPService>
</fx:Declarations>
<s:Label x="204" y="182" text="欢迎您第{a}访问本站"/>
</s:Application>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询