loxxy
loxxy

Reputation: 13151

Can flash download html from random webpage?

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:

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' :

enter image description here

Upvotes: 1

Views: 864

Answers (3)

IphStich
IphStich

Reputation: 99

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.

Upvotes: 1

Eugeny89
Eugeny89

Reputation: 3731

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

Upvotes: 1

23tux
23tux

Reputation: 14736

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.

Upvotes: 1

Related Questions