简体   繁体   English

我如何知道请求是否来自Flash swf?

[英]How do i know if the request came from flash swf?

I have an application developed in flash, and I need to access some php files. 我有一个用flash开发的应用程序,我需要访问一些php文件。 so the php file return some data if the access is came from swf. 所以如果访问来自swf,php文件会返回一些数据。 How can i identify if the request came from flash or not? 如何识别请求是否来自闪存?

without passing get/post variables to php. 没有将get / post变量传递给php。

User agent/Referer possibly. 用户代理/ Referer可能。 Keep in mind that requests can easily be forged 请记住,请求很容易被伪造

I don't think there really is a reliable way of detecting whether Flash made the request. 我认为没有一种可靠的方法来检测Flash是否提出了请求。 Flash doesn't allow you to set the user-agent, and there are a lot of restrictions on what headers can be set. Flash不允许您设置用户代理,并且对可以设置的标头有很多限制。

Take a look at http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/net/URLRequestHeader.html 请查看http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/net/URLRequestHeader.html

as John Ballinger suggested, you could set your own header using this and look for that header in the PHP page. 正如John Ballinger建议的那样,您可以使用此设置自己的标头,并在PHP页面中查找该标头。

This is in response to John Ballinger 's answer: 这是对John Ballinger的回答的回应:

import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestHeader;

var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://www.mydomain.com/myapp.php");
var header:URLRequestHeader = new URLRequestHeader("custom-header-name", "value");
request.requestHeaders.push(header);
try {
    loader.load(request);
} catch (error:Error) {
    trace("Unable to load requested document.");
}

You must also make sure to modify your crossdomain.xml to allow http headers as follows: 您还必须确保修改crossdomain.xml以允许http标头,如下所示:

<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
    <allow-access-from domain="*.mydomain.com" />
    <allow-http-request-headers-from domain="*.mydomain.com" headers="*" />
</cross-domain-policy>

You cannot tell that it is coming from flash as flash actually uses the browser to do the request. 您无法分辨它是来自闪存,因为闪存实际上使用浏览器来执行请求。

But in your flash request you could add your own header to the HTTP request (you can do this pretty easily in flash). 但是在您的Flash请求中,您可以将自己的标头添加到HTTP请求中(您可以在Flash中轻松完成此操作)。 That way you can see if the request is coming from Flash. 这样您就可以看到请求是否来自Flash。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM