0

I am running an embedded flash 'swf' inside a LAN network with a proxy server. Proxy server interrupts some urls and returns my usage information. I am trying to access this information by sending those urls. I can see this traffic in firebug ,But the URLLoader does not seem to read it. Neither Complete event or progress event get fired. I tried URLStream with a timer also,but availableBytes were always zero.Is it possible to read this information?

  private var getLoader:URLLoader = new URLLoader();
  private var sendRequest:URLRequest = new URLRequest();
  public function XDomain() {
   sendRequest= new URLRequest("requesturl");
   getLoader.addEventListener(Event.COMPLETE, eventHandler);
   getLoader.addEventListener(ProgressEvent.PROGRESS,eventHandler2);
   getLoader.load(sendRequest);
  }
  private function eventHandler(event:Event):void {
    trace("running");
  }
  private function eventHandler2(event:ProgressEvent):void {
   trace("runninhg progresss");
  }

Thanks in advance // Edit: I had this security error

[SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048"]
feminkk
  • 1,135
  • 2
  • 14
  • 18
  • Please listen to SecurityErrorEvents and HTTPStatusEvents and lets see what it says. – phasma Dec 27 '16 at 02:25
  • @Jacob HTTPStatusEvent listner is blocking my code.Is there something I am missing? //getLoader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, httpHandler);// .trace after this does not run. – feminkk Dec 27 '16 at 09:42
  • _"URLStream with a timer"_ why??? Is there a result if you let it work naturally, without a timer interrupting? URLStream is your best bet since it gives raw access to server response. If still failing, show your URLStream code or give testable link that re-produces your issue. – VC.One Dec 27 '16 at 17:16
  • None of the events were firing that is why i used a timer to return getLoader.bytesAvailable .I guess it wont do anything. – feminkk Dec 27 '16 at 17:35
  • About events you have an `import flash.events.*;` in your code? Does it help to add that? The _not running_ `trace` is inside httpHandler function right?... Anyways `URLLoader` itself isn't going to show you any server's response text. Show me how you instead tried `URLStream` (short example, testable in our own compilers). I'm seriously struggling to **not** make it work in my own tests so either your URLStream code is wrong or else share an example/testable link to the crazy server. – VC.One Dec 27 '16 at 23:52
  • Thanks again.In the above example itself If i replace URLLoader with URLSream that is a minimal example of my setup. I have trace functions for getLoader.bytesAvailable inside the progress event. but those are irrelevant without the event actually getting fired.// Yes i do already have // import flash.events.*;// – feminkk Dec 28 '16 at 06:09
  • `sendRequest= new URLRequest("https://www.google.com");` does that URL at least get some progress event firing? For _Google.com_ I got four lots of your `runninhg progresss` showing (in Flash IDE) when using your code with URLStream as a replacement. Also your first line of code.. `getLoader:URLLoader() = new URLLoader();` should be `getLoader:URLLoader = new URLLoader();` If you got no error showing here then I wonder if same issue is responsible for no traces in other parts of code? – VC.One Dec 28 '16 at 09:49
  • Also because it's URLStream so trace the incoming data like this : `trace(event.target.readUTFBytes(event.target.bytesAvailable) );` – VC.One Dec 28 '16 at 09:52
  • URLLoader() was a typo.//I dont get progress events for google.com . Flash requests https://www.google.com/crossdomain.xml and retrieves it .But it shows the error again not revealing the data . I am compiling it with wonderfl.net and running in firefox on linux. // I have a setup a server with a crossdomain.xml for testing. which works perfectly i can make GET and POST requests successfully . I think that shows code part is fine.// About event.target part ,since I have defined getLoader with a 'new' isn't it available directly without using event.target (Anyway it doesn't matter ). – feminkk Dec 28 '16 at 10:55
  • See if [**this Answer**](http://stackoverflow.com/questions/36476683/youtube-flash-api-as3-not-working-in-firefox-but-in-chrome/36618114#36618114) makes sense to you somehow. I think Firefox expects both your swf and the contacted server to be running on `https`, if both sides are not matching (`http` or `https`) then it will block your swf accessing any data. I also never compiled with Wonderfl.net (maybe using a website brings its own new issues)... PS: `new` is just new unique instance of something, `event.target` is to say whichever object (target) has this `eventListener` attached... – VC.One Dec 29 '16 at 09:00

1 Answers1

0

"But the URLLoader does not seem to read it..."

Use URLStream (without a timer, cos what does that even achieve?) to reach the link and inside your related progressEvent use a readUTFBytes to get any text response data given by that link's server. Use progressEvent to also check size of any received bytes (the event fires multiple times, getting 64kb packets, until full data is downloaded).

about Error #2048:
URLloader is a decoder for visual data (jpg, png, swf, text) but for non-text data it expects a crossdomain.xml to exist at the other server you are accessing the swf from (both sides must also have a matching same http or https. Again best way to by-pass this is to just load the bytes into a byte array (via URLStream but the progressEvents now should write to your byte array) then later use URLLoader.loadBytes( yourSWFBytes );

VC.One
  • 14,790
  • 4
  • 25
  • 57
  • Thanks for the reply . Events does not fire with URLStream either .I get the same security error too. – feminkk Dec 27 '16 at 17:25
  • _"Events does not fire"_ Then there is **no connection** at all. _"I get the same security error too"_ False, there isn't a security issue when decoding your own bytes. There isn't even an issue to fill those bytes by `readBytes` from any external server. That's why its an **actual workaround**. By the time you use `getLoader.load(myBytes);` that `load` is told to decode your own image bytes, if instead you give some external URL (like that `sendRequest`) then you force it assume you're stealing content so it has security error when not finding permissions file existing at external server. – VC.One Dec 27 '16 at 19:59
  • [**`Edit`**](http://stackoverflow.com/posts/41331039/edit) your Question showing an example of how you handle URLStream, Bytes and Decoding process. Both your above conditions are unknown in that system. PS: So if URLStream is not running (no progress detected) then how do you later get the security error? Did the bytes size match the swf file size before you tried to decode (display) with URLLoader? Anyways I'll look at your code if you update... – VC.One Dec 27 '16 at 20:10
  • I have embedded the swf on an html file.The network panel shows me connection and response from the server.I can see the Get request and response from the server .The network responds but flash for some reasons(security may be) does not accept the data( I guess) .//Complete event and progress event does not fire ,but security event does fire and gave me the response error 2048.bytesize is always zero both totalsize and availablesize. Thanks – feminkk Dec 27 '16 at 21:01
  • The actual request flash makes is a server/crossdomain.xml . But the server will respond with usage information along with an error message. I am looking for the information part in there. – feminkk Dec 27 '16 at 21:24
  • I hear you but... **(1)** The only way to get such info via AS3 code is using the URLStream API since that handles any data sent by server. **(2)** You "record" the received bytes by copying into some bytearray using a **progressEvent**, which you say doesn't fire once and so with that issue you could never do steps 1 or 2.. **(3)** URLLoader's `load` command is for **decoding image formats** (or SWF), it is the wrong tool if you don't expect to load valid bytes for some jpg, png or swf. **(4)** URLLoader strangely also checks source URL of loaded content to see if you have rights to display. – VC.One Dec 27 '16 at 23:07