当使用URLRequest发布表单时,如何包含来自浏览器会话的Cookie? [英] When POSTing a form with URLRequest, how to include cookies from browser session?

查看:261
本文介绍了当使用URLRequest发布表单时,如何包含来自浏览器会话的Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(参考



当我使用URLRequest进行POST时,它会自动包含来自Flash托管的浏览器会话的Cookie吗?

解决方案

提供Cookie网域(托管Flash控件的网页和您要发布到的网址)匹配,则是,浏览器Cookie与默认情况下的请求一起发送。作为一个快速示例(此处的工作版本),我把一个简单的ColdFusion页面托管包含以下代码的SWF:

 < mx:Script& 
<![CDATA [

私人函式btn_click():void
{
var req:URLRequest = new URLRequest(http://test.enunciato .org / test.cfm);
req.method = URLRequestMethod.POST;

var postData:URLVariables = new URLVariables();
postData.userName =Joe;
postData.userCoolness =very-cool;

req.data = postData;
navigateToURL(req);
}

]]>
< / mx:Script>

< mx:Button click =btn_click()label =Submit/>

...在该页面中,我设置了一个名为USERID的12345。点击提交并导航到另一个CFM后,我的服务器日志显示请求中传递的Cookie:


POST /test.cfm HTTP /1.1 Mozilla / 5.0

ASPSESSIONIDAASRDSRT = INDFAPMDINJLOOAHDELDNKBL;

JSESSIONID = 60302395a68e3d3681c2;

USERID = 12345

test.enunciato.org 200


如果你自己测试一下,你也会看到postData。 p>

有意义吗?


(With reference to this answer:)

When I POST with a URLRequest, does it automatically include cookies from the browser session in which Flash is hosted? If not, how can I make it include them, or if necessary retrieve them and include them myself?

解决方案

Provided the cookie domains (of the page hosting the Flash control and the URL to which you're posting) match, then yes, the browser cookies get sent with the request by default. As a quick example (working version here), I've thrown together a simple ColdFusion page hosting a SWF containing the following code:

<mx:Script>
    <![CDATA[

        private function btn_click():void
        {
            var req:URLRequest = new URLRequest("http://test.enunciato.org/test.cfm");
            req.method = URLRequestMethod.POST;

            var postData:URLVariables = new URLVariables();
            postData.userName = "Joe";
            postData.userCoolness = "very-cool";

            req.data = postData;
            navigateToURL(req);
        }

    ]]>
</mx:Script>

<mx:Button click="btn_click()" label="Submit" />

... and in that page, I set a cookie, called "USERID", with a value of "12345". After clicking Submit, and navigating to another CFM, my server logs reveal the cookie passed through in the request:

POST /test.cfm HTTP/1.1 Mozilla/5.0
ASPSESSIONIDAASRDSRT=INDFAPMDINJLOOAHDELDNKBL;
JSESSIONID=60302395a68e3d3681c2;
USERID=12345
test.enunciato.org 200

If you test it out yourself, you'll see the postData in there as well.

Make sense?

这篇关于当使用URLRequest发布表单时,如何包含来自浏览器会话的Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆