Can flash download html from random webpage?

2019-08-08 22:12发布

问题:

I have given up on trying to get the source of a webpage (I don't own this server) in AS3. All it does is throw an sandbox violation error (2048). So far I have come to a conclusion that the only solutions possible are:

  • Make my web server serve the content to the swf.
  • Make a proxy server for the swf with crossdomain.xml.

Somehow, both the options are being rejected by my seniors & I am being pushed for a better solution.

I don't have any idea if anything else is possible, does anyone here have one??


EDIT : Maybe some hack where 'A' may not need the policy file to communicate directly with 'B' :

回答1:

I think a simple PHP proxy is the easiest way:

<?php
  echo system ("curl \"".$_GET["url"]."\"");
?>

And call it with

http://www.yourserver.com/pathtoyourscript/proxy.php?url=http://www.yoururl.com

not tested, but in general it should work.



回答2:

As I can see you run your app in browser, I can suggest downloading HTML with javascript (e.g. with XMLHttpRequest), and then passing it to your app via ExternalInterface. I'm not sure that it's better then solutions you posted. Anyway it's client-side hack and different from yours.

UPD: another way is to create an invisible frame and do
document.getElementByID('frameID').src=url; there, after that pass document.getElementByID('frameID').innerHtml to swf with ExternalInterface



回答3:

AS3 has a few ways of loading html from web pages. The most convenient is probably to use a URLLoader.load() function.

    const targetURL:String = "www.example.com"

    var quest:URLRequest = new URLRequest()
    quest.url = targetURL

    var oader:URLLoader = new URLLoader()
    oader.addEventListener(Event.COMPLETE, doSomething)
    oader.load(quest)

For more information: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html

If done correctly, this should load the web page's html as a string.

If I understand your problem correctly, this probably isn't working. So of course, there are a few work-arounds you could use.

I remember in an old project I was doing with a similar obstacle, my solution was to have an external SWF written in AS2 (hosted on another server, my FTP server). My main SWF loaded the AS2 SWF using Loader.load(). Communicating between the two SWFs using LoacalConnections (link). For some reason, the server I had uploaded my SWF to didn't allow AS3's URLLoader.load() but allowed AS2's sendAndLoad().

Another work-around I used, I used an external AS3 SWF, for a similar reason.

I recommend you experiment with various methods, your specific work-around may not be what I have recommended, however my recommendations may point you in the right direction.

And of course the good thing with my work-around is that your seniors won't notice a difference. The main SWF will be hosted on the same server, and will function as intended, with a minimal increase to load time.