Flash Player是否自动传输会话Cookie? [英] Does Flash Player transmit session cookies automatically?

查看:229
本文介绍了Flash Player是否自动传输会话Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法访问Flash电影中的HTTP Cookie,但我现在已经反复阅读,说Flash Player应该自动处理会话Cookie。我可以,但是,没有找到任何文档,这确实不工作与我的Flex客户端运行使用默认的JSESSIONID cookie的Struts后端。

There's no access to the HTTP cookies from within a Flash movie, but I now have repeatedly read that Flash Player is supposed to take care of session cookies automatically. I could, however, not find any documentation about this, and it sure didn't work with my Flex client running against a Struts backend using the default JSESSIONID cookie.

,Flash Player是否处理会话cookie或者不是,如果是,我该如何设置呢?

So, does Flash Player handle session cookies or doesn't it, and if it does, how do I set it up?

推荐答案

来自Flash的HTTP请求通过浏览器发送 - 因此,Cookie是自动传输的。事实上,我目前正在做一个网站,在HTML页面中处理登录(并因此设置会话cookie),然后将用户转发到仅Flash页面()。 Flash页面正在使用 URLLoader & URLRequest ,我可以验证其中每一个的会话cookie。

The HTTP requests from Flash are sent through the browser - so yeah, the cookies are transmitted automatically. In fact, I am currently doing a site that handles logging-in (and hence setting the session cookie) in an HTML page and then forwards user to a Flash only page (). The flash page is sending a lot of requests to the server using URLLoader & URLRequest and I am able to verify the session cookie for each of those.

也就是说,您可以访问HTTP来自Flash的Cookie使用 ExternalInterface.call()。确保SWF嵌入代码中的 allowScriptAccess 设置为适当的值。 p>

That said, you can access HTTP cookies from Flash using ExternalInterface.call(). Make sure allowScriptAccess in the SWF embedding code is set to appropriate value.

var cookies:String = ExternalInterface.call("function()
    {
        return document.cookie;
    }()");






更新:在Flash中),但你可能是正确的 - Flash可能会忽略 Set-Cookie (或所有)响应头。不幸的是,Flash不允许我们访问响应头。但是由于可以在AJAX响应中访问响应头(使用 xhr.getResponseHeader ),您可以使用 ExternalInterface 并将登录部分外包给AJAX。 抓取AJAX响应中的标头,并使用javascript设置Cookie(根据此SO线程,浏览器会自动执行)。设置完成后,Flash发送的后续请求将包含会话Cookie。


Update: I haven't tried that (login in flash), but you might be right - Flash might be ignoring the Set-Cookie (or all) response headers. And unfortunately Flash does not let us access response headers either. But since it is possible to access the response headers in an AJAX response (using xhr.getResponseHeader) you can use ExternalInterface and outsource the login part to AJAX. Grab the headers in the AJAX response and set the cookie using javascript (according to this SO thread, browser will do that automatically). Once set, subsequent requests sent from flash would include the session cookie in them.

使用 ExternalInterface.addCallback 方法从javascript注册一个可调用的flash方法。

Use the ExternalInterface.addCallback method to register a flash method to be callable from javascript.

这篇关于Flash Player是否自动传输会话Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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