flex中怎么获取cookie

 我来答
xiangjuan314
2016-04-23 · TA获得超过3.3万个赞
知道大有可为答主
回答量:2.9万
采纳率:0%
帮助的人:3130万
展开全部
<%@ 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>
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式