使用 URLRequest 发布表单时,如何包含浏览器会话中的 cookie?
(参考这个答案:)
当我使用 URLRequest 进行 POST 时,它是否会自动包含来自托管 Flash 的浏览器会话的 cookie? 如果没有,我怎样才能让它包含它们,或者如果有必要的话,我自己检索它们并包含它们?
(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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果 cookie 域(托管 Flash 控件的页面和您要发布到的 URL)匹配,那么默认情况下,浏览器 cookie 会随请求一起发送。 作为一个简单的示例(此处的工作版本),我整理了一个简单的 ColdFusion 页面,其中托管SWF 包含以下代码:
...在该页面中,我设置了一个名为“USERID”的 cookie,其值为“12345”。 单击“提交”并导航到另一个 CFM 后,我的服务器日志显示请求中传递的 cookie:
如果您自己测试一下,您也会在那里看到 postData。
合理?
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:
... 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?
我假设您只是不想包含用于服务器端身份验证目的的会话 ID 之类的内容。
从 AS 获取浏览器 cookie(需要启用 JavaScript,对于大多数用户来说应该不是问题)
然后,在使用 URLRequest 对象时:
请注意 Firefox 不会发送会话的 cookie使用 URLRequest,您将需要一个与上面类似的解决方案来解决这个问题。
I'm assuming you just wan't to include something like a session id for authentication purposes server-side.
To get the browser cookie from AS (needs javascript enabled, shouldn't be a problem for most users)
Then, when using your URLRequest object:
Take note that Firefox does not send the cookies of the session along with a URLRequest, you will need a solution similar to the one above to overcome this problem.
不确定闪光灯。 但是你不能序列化cookie并将其放入URL中吗?
也许您想加密数据或以纯文本形式传输数据,但它可能看起来像:
url:
等
(或者我遗漏了一些东西?)
Not sure about flash. But couldn't you serialize the cookie and put it into the URL?
Maybe you would want to encrypt the data or transmit it in plain text but it might look like:
url:
etc
(or I am missing something?)