as3 URLLoader always failing with IOError - actionscript-3

I'm having problems with URLRequest in a flex application, it fails with whatever url I try:
var r:URLRequest = new URLRequest("http://stackoverflow.com");
var l:URLLoader = new URLLoader();
l.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void {
trace(e);
});
l.load(r);
This is the error I get:
[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Error de secuencia. URL: http://stackoverflow.com"]
Obviously the url is not down as I'm using it right now to post this. I've also tried others such as google.com which work ok in my browser, and I get the same error. Any one knows what could be the problem?
Thank you

Related

sendToURL not working in flashplayer 14

This piece of code is working in flashplayer 11 but it's not working in flashplayer 14.
AS3 code :
private function savePDF(pdfBinary:ByteArray, urlString:String):void{
try{
//result comes back as binary, create a new URL request and pass it back to the server
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var sendRequest:URLRequest = new URLRequest(urlString);
sendRequest.requestHeaders.push(header);
sendRequest.method = URLRequestMethod.POST;
sendRequest.data = pdfBinary;
sendToURL(sendRequest);
} catch (e:Error) {
// handle error here
trace("Error in savePDF "+e.message);
trace("StackTrace : "+e.getStackTrace());
}
}
and these are the errors I got :
Error in savePDF Error #3769: Security sandbox violation: Only simple headers can be used with navigateToUrl() or sendToUrl().
StackTrace : SecurityError: Error #3769: Security sandbox violation: Only simple headers can be used with navigateToUrl() or sendToUrl().
at global/flash.net::sendToURL()
at Export2Publish/savePDF()[my_project_dir\src\Export2Publish.mxml:158]
at Export2Publish/GeneratePDF()[my_project_dir\src\Export2Publish.mxml:386]
at Export2Publish/getUrl()[my_project_dir\src\Export2Publish.mxml:138]
at Export2Publish/___Export2Publish_Application1_creationComplete()[my_project_dir\src\Export2Publish.mxml:3]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[my_framework_dir\src\mx\core\UIComponent.as:9051]
at mx.core::UIComponent/set initialized()[my_framework_dir\src\mx\core\UIComponent.as:1167]
at mx.managers::LayoutManager/doPhasedInstantiation()[my_framework_dir\src\mx\managers\LayoutManager.as:698]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/callLaterDispatcher2()[my_framework_dir\src\mx\core\UIComponent.as:8460]
at mx.core::UIComponent/callLaterDispatcher()[my_framework_dir\src\mx\core\UIComponent.as:8403]
Any fix for this issue ?
You can start by using a try and catch like this :
try {
sendToURL(request);
}
catch (e:Error) {
// handle error here
}
If the problem is not visible on dev environment, I recommand you to install a flash debug player which you can download here : Flash Player Downloads to see what kind of error your code will fire.
If your code is fine, in dev and prod environment, you should debug your server side script.

Load External Image in Flex Mobile App

I am trying to load images from my website on my Flex Mobile Application. When I run the code using my localhost, everything works perfectly. However, when I try to load the images from my live website, I get the error:
IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2036: Load Never Completed. URL: http://sortsports.com/images/players/nfl/sketch/8850x300.jpg" errorID=2036]
I am using a Loader to load the image and a LoaderContext setting checkPolicyFile to false.
var lc:LoaderContext = new LoaderContext();
lc.checkPolicyFile = false; // bypass security sandbox / policy file - does this effect quality when scaling? - See more at: http://www.onegiantmedia.com/as3--load-a-remote-image-from-any-url--domain-with-no-stupid-security-sandbox-errors#sthash.ZRnTf99k.dpuf
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, playerImageLoadCompleteHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);
trace('loading: ' + remoteFileUrl);
loader.load(new URLRequest(remoteFileUrl), lc); // add a loader context to not check the policy file
private function playerImageLoadCompleteHandler(event:Event):void
{
var loaderInfo:LoaderInfo = event.target as LoaderInfo;
playerImage.source = loaderInfo.content;
}
private function loaderIOErrorHandler(ev:Event):void{
trace("Image not found and ioError: " + ev);
playerImage.source = 'k';
}
I also have a crossdomain policy in the root of the url:
<?xml version="1.0"?>
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*" to-ports="*"/>
</cross-domain-policy>
I load the crossdomain like this:
Security.loadPolicyFile(Globals.currentDomain + "/crossdomain.xml");
And I try to allowDomain
//Security.allowDomain('http://sortsports.com/');
But I get an error
SecurityError: Error #3207: Application-sandbox content cannot access this feature.
So I put it in the try catch:
try {Security.allowDomain("*");}catch (e) { trace("e.message: " + e.message); };
Again, the code works great on localhost. I don't think using a proxy is a possibility as this is a mobile app.

Flash cannot setup XMLSocket

I just started a project in flash, but it can't startup XMLSocket.
My code:
import Network.CommunicationBootstrap;
var network:CommunicationBootstrap = new CommunicationBootstrap();
network.start("127.0.0.1", 30000);
Package Network classs CommunicationBootstrap:
package Network {
import flash.net.XMLSocket;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
public class CommunicationBootstrap {
private var socket:XMLSocket = new XMLSocket();
public function CommunicationBootstrap() {
socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
}
public function start(ip:String, port:int):void {
this.socket.connect(ip, port);
trace("Testing this out!");
}
private function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
}
}
What my errors are:
ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Socket Error. URL: 127.0.0.1"]
securityErrorHandler: [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048: Security sandbox violation: file:///C|/Users/iufrs/Documents/AS3/1/Torn.swf cannot load data from 127.0.0.1:30000."]
(gotten by trace and the 2 events)
This is (as the message hints) due to the sandbox your swf is running in.
from the docs
Local file describes any file that is referenced by using the file:
protocol
Which is what you are doing here.
Further:
The local-with-filesystem sandbox—For security purposes, Flash Player
places all local SWF files and assets in the local-with-file-system
sandbox, by default. From this sandbox, SWF files can read local files
(by using the URLLoader class, for example), but they cannot
communicate with the network in any way. This assures the user that
local data cannot be leaked out to the network or otherwise
inappropriately shared
This is what is causing you to see the error.
If you intend your swf to be hosted by a web server, then you should make sure the swf can be loaded from your webserver running on 127.0.0.1, and you should load it over http, e.g. as http://127.0.0.1/YourSwf.swf
If you want to run your sef from the filesystem, you need to compile it to run in the 'local-with-networking' sandbox, the link explains how.
.

Getting Error #2032: Stream Error. in Flash while sending url request to server

I am sending http request to server via URLLoader in Flash. My Code is:
var urlLoader:URLLoader=new URLLoader();
var urlRequest:URLRequest=new URLRequest();
var urlparam:URLVariables= new URLVariables();
urlparam.req=JSON.encode(workout);
urlRequest.method="POST";
urlRequest.data=urlparam;
urlRequest.url="http://mydomain.com/saveworkout.php";
urlLoader.addEventListener(Event.COMPLETE,loadCompleted);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR,loadError);
urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityError);
urlLoader.load(urlRequest);
}
private function loadError(event:IOErrorEvent):void{
trace("Stream Error="+event.text);
}
private function securityError(event:SecurityErrorEvent):void{
trace("Security Error="+event.text);
}
private function loadCompleted(event:Event):void{
var urlLoader:URLLoader=event.target as URLLoader;
trace(urlLoader.data);
}
This code works fine when I test it locally and send request to localhost, but giving me Error #2032: Stream Error. At remote server codeigniter framework is being used. I also the crossdomain.xml in the httpdocs directory, and also cross check the request url. Request url opens fine directly in the web browsers. Any idea?
Thanks & Regards,
Check headers in server response.
Maybe it's not of right MIME type or even corrupt.
Browser show it's ok, but in reality its broken. Use Firebug, or Tamperdata plugin for Firefox.

Reading server error messages for a URLLoader

I have an URL loader with the following code:
public function getUploadURL():void {
var request:URLRequest = new URLRequest();
var url:String = getPath();
// Adds time to prevent caching
url += "&time=" + new Date().getTime();
request.url = url;
request.method = URLRequestMethod.GET;
_loader = new URLLoader();
_loader.dataFormat = URLLoaderDataFormat.TEXT;
_loader.addEventListener(Event.COMPLETE, getBaseURL);
_loader.addEventListener(IOErrorEvent.IO_ERROR, onGetUploadURLError);
_loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, getHttpStatus);
_loader.load(request);
}
My problem is that this request might be wrong, and so the server will give me a back a 400 Bad Request, with a message to explain the error. If the Event.COMPLETE, I can see some message (a response) back from the server in the "data" field of the Event, but if onGetUploadURLError or getHttpStatus is called, it just says that the error code is 400 but does not show me the message associated with it.
The "data" field is undefined in getHttpStatus and it is "" in onGetUploadURLError.
On the contrary, in getBaseURL, I get: {"ResponseMetadata":{...}}
I checked and I do get a similar response in my browser for a wrong request, but I cannot see it.
Any idea how I can please get the message?
Thank you very much,
Rudy
Flash does not handle HTTP status codes very well. Here is a blog post with comments from an Adobe employee saying the problem is actually the plug-in limitations. The Adobe employee points to a library for doing HTTP requests using AS3 through sockets but I doubt that would be highly efficient (compared to having the plugin-in hand requests off to the browser).
Standard practice on all projects I have ever worked on was to always send a 200 OK and add a error key onto the message.
edit: also see this bug which is exactly your issue.