Flash - HTTP请求在本地主机上不起作用 [英] Flash - HTTP requests won't work on localhost

查看:188
本文介绍了Flash - HTTP请求在本地主机上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我试图解决一些我没有建立起来的东西,那个项目的人确保我离开的时候工作正常,尽管我离开他之后没有碰到一个版本似乎有相同的问题。我在编程方面也有点新意,所以让我知道我在第一篇文章中是否遗漏了重要的信息,并且会尝试添加更多信息。



我有一个在线托管的Flash应用程序,充当用Delphi编写的服务器应用程序的客户端。大部分的沟通都是使用套接字来完成的,上传数据文件和下载结果文件是使用HTTP请求完成的,只要用户正在使用另一台计算机上的服务器实例,就可以正常工作。但是,如果用户在自己的计算机上安装了服务器应用程序,并尝试使用指定localhost作为url,那么套接字通信仍然有效,但HTTP请求不会。


$ b $所有基于套接字的通信都可以正常工作,并且当它不在本地主机上时,所有的HTTP请求都可以正常工作,这就是为什么这对我来说太神秘了。我已经尝试更改服务器调度的Flash跨域策略文件,完全放宽,所有端口,所有域,所有http请求标头,仍然没有运气。



Flash应用程序将在大多数时间无限期地等待本地主机,直到关闭服务器应用程序,然后发出以下错误消息:

 错误#2044:未处理的SecurityErrorEvent :. text =错误#2048:安全沙箱违规:http://abcde.com/Testing.swf无法从http:// localhost:2188 / guid = 53D569A8-56EA-4AC2-BDA0-2F43525E1378加载数据。 

我试过在多台计算机上托管它,每台机器都可以访问另一台实例,但是当它尝试使用自己的实例时,它将不起作用。



另外,如果我简单地把 http:// localhost:2188 / guid = 53D569A8-56EA-4AC2-BDA0-2F43525E1378 进入网络浏览器,结果文件我试图让弹出窗口很好。



Flash应用程序中的代码块试图下载文件:
$私有函数downloadFile():void
{
trace(downloadFile:+ this.guid +from + this.server。 URL);
fileRef.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
fileRef.addEventListener(ProgressEvent.PROGRESS,downloadProgressHandler);
var ur:URLRequest = new URLRequest(http://+ _server.URL +:+ _server.port);
ur.url + =/ guid =+ _guid;
ur.method = URLRequestMethod.GET;
fileRef.download(ur,_filename);
_downloadStart = true;



$ b $ p
$ b如果有人有任何的见解,我会感激,因为我是完全的出于想法这里。

解决方案

这是Flash播放器的安全模型的限制。为了解决这个问题,你可以将你的闪存打包成一个AIR应用程序,并解除了许多这些安全限制。



如果你的闪存文件,而不是在本地访问.swf文件。



另一件你不能做的事就是从Flash播放器中访问本地文件,这是另一个您可以使用AIR运行时执行的操作的示例,您无法在Flash Player中执行操作。


First off, I'm trying to fix something that I didn't build to begin with and the guy who's project it was assures me it was working fine when he left, although a version I haven't touched since he left seems to have the same issues. I'm also a bit new to programming in general so let me know if I've left out important information in my first post and I will try to add more info.

I have a flash application hosted on-line that acts as a client for a server application written in Delphi. Most of the communication is done using sockets, which work fine. Uploading data files and downloading results files is done using HTTP requests, which work fine as long as the user is making use of an instance of the server on another computer. However, if the user has the server application installed on their own computer and attempts to use it specifying localhost as the url, the socket communication still works, but the HTTP requests don't.

All the socket based communication works fine and, when it is not on the localhost, all the HTTP requests work fine as well, which is why this is so mystifying to me. I've tried changing the flash cross-domain policy file that the server dispatches to be completely permissive, all ports, all domains, all http-request-headers, and still no luck.

The Flash app will sit waiting for localhost indefinitely most of the time until I close the server application, and then give this error message:

Error #2044: Unhandled SecurityErrorEvent:. text=Error #2048: Security sandbox violation: http://abcde.com/Testing.swf cannot load data from http://localhost:2188/guid=53D569A8-56EA-4AC2-BDA0-2F43525E1378.

I've tried hosting it on multiple computers, each machine can access the instance on another just fine, but won't work when it tries to work with its own instance.

Also, if I simply put http://localhost:2188/guid=53D569A8-56EA-4AC2-BDA0-2F43525E1378 in to a web browser, the results file I am trying to get pops up just fine.

Here's the chunk of code in the flash app that attempts to download the file:

private function downloadFile():void
{
    trace("downloadFile: " + this.guid + " from " + this.server.URL);
    fileRef.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    fileRef.addEventListener(ProgressEvent.PROGRESS, downloadProgressHandler);
    var ur:URLRequest = new URLRequest("http://" + _server.URL + ":" + _server.port);
    ur.url += "/guid=" + _guid;
    ur.method = URLRequestMethod.GET;
    fileRef.download(ur, _filename);
    _downloadStart = true;
}

If anyone has any insight at all, I would be grateful because I am completely out of ideas here.

解决方案

This is a limitation of the flash player's security model. To get around this problem, you can package your flash as an AIR application and have many of these security restrictions lifted.

You may also have better success if you host your flash file on a web server instead of accessing the .swf locally.

Another thing that you won't be able to do is access local files from the flash player, this is another example of something you can do with the AIR runtime that you cannot do in the flash player.

这篇关于Flash - HTTP请求在本地主机上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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