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

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

问题描述

无法从 Flash 电影中访问 HTTP cookie,但我现在反复读到 Flash Player 应该自动处理会话 cookie.但是,我找不到任何关于此的文档,而且它肯定不适用于使用默认 JSESSIONID cookie 对 Struts 后端运行的 Flex 客户端.

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.

也就是说,您可以使用 ExternalInterface.call().确保 SWF 嵌入代码中的 allowScriptAccess 设置为适当的值.>

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),您可以使用 ExternalInterfaceoutsource 登录部分到 AJAX.获取 AJAX 响应中的标头并使用 javascript 设置 cookie(根据 this SO thread,浏览器会自动执行).设置后,从 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天全站免登陆