问题描述
(参考),我把一个简单的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:
如果你自己测试一下,你也会看到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:
If you test it out yourself, you'll see the postData in there as well.
Make sense?
这篇关于当使用URLRequest发布表单时,如何包含来自浏览器会话的Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!