URLLoader not working for HTML5

Trying to use this simple script on Openfl 5.1.3

var urlLoader = new URLLoader ();
urlLoader.addEventListener (Event.COMPLETE, function (_) {

    trace (urlLoader.data);

});
urlLoader.load (new URLRequest ("http://www.google.com"));

Works on flash but not on html5.

Probably it is due to CORS - https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

Hmm. But it does not seem to be working even if there is some php file on the same server in the same folder. Neither on the local host nor on the server.

Our openfl test html5 local test server is probably not going to work with a PHP script, but you could test a txt file or other standard file to see if it completes

Ya, I understand that haxe server cannot process PHP. So in my case, I had the test PHP file on the xampp server installed on my machine, running on a different port.

The problem occurs when I test on the localhost server. It’s not able to get data from anywhere, whether it’s PHP or any text file placed on localhost or any remote location. ( For example my remote location is : freelancesoftwareservices.com/data/my.php )

However, when I uploaded all the html-build files on my hosting server, it successfully loads data from both, the PHP as well as the text file.

Looks like the problem ( as restorer pointed out CORS ) is something similar to Flash’s sandbox violation errors. So, I think there is no way to test data loading on localhost. I will always need to upload it on the remote hosting server for testing.

Anyway, thanks for the help. :slight_smile:

You could openfl build html5 into a directory running on your local XAMPP server, so both are running on the same server. Perhaps that would work for development?

1 Like

Yes, that works. I can test locally now. :slight_smile: