Problem sending URL post request to server


I have problem sending a JSON obejct from a flash program to a server. It looks like the program get stuck in URLloader.load() call. It would be to great help if someone knew what was wrong.
The server is currently just listening on port 8080.

class Main extends Sprite {

public function new () {
	super ();

	var fileContents:String = "Something";
	var name:String = "name1";

	var urlRequest:URLRequest = new URLRequest("http://localhost:8080");
	urlRequest.method = URLRequestMethod.POST; = Json.stringify({name:name, content:fileContents});
	urlRequest.contentType = "application/json";
	urlRequest.requestHeaders.push( new URLRequestHeader( 'Cache-Control', 'no-cache' ) );

	var textField: TextField = new TextField();
	var titleFormat = new TextFormat();
	titleFormat.color = 0x000000;
	titleFormat.size = 40;
	textField.defaultTextFormat = titleFormat;
	textField.text = "Click to upload";
	textField.x = 500;
	textField.y = 500;
	textField.width = 500;
	textField.height = 500;
	textField.addEventListener(MouseEvent.CLICK, function(e){
		var urlLoader:URLLoader = new URLLoader();
		urlLoader.dataFormat = URLLoaderDataFormat.TEXT;

		urlLoader.addEventListener( Event.COMPLETE, onComplete);
		urlLoader.addEventListener( HTTPStatusEvent.HTTP_STATUS, onHttpStatus);
		urlLoader.addEventListener( IOErrorEvent.IO_ERROR, onIOError );
		urlLoader.addEventListener( SecurityErrorEvent.SECURITY_ERROR, onSecurityError );

		urlLoader.load( urlRequest );

For flash, you need to add some permissions to allow your program to connect to a distant server (if you compile in debug mode, you should see an error message telling you there is some flash permission error)
Try to compile with the -Dnetwork-sandbox flag and it should work :wink:

Thanks! Now it doesn’t get stuck in the URLLoader.load call anymore, but I get this security error event:
"SecurtyErrorEvent type=“securityError” bubbles=false cancelable=false eventPhase=2 text=“Error #2170”.
The server also get something on port 8080, but it is seen as a GET not a POST.

Well it depends on the configuration of your server. I you test your flash application from a webpage not hosted on your server, you may need a crossdomain.xml policy file. When testing it locally, I had to put a crossdomain.xml file at the root of my local apache server with this content to make it work:

<?xml version="1.0"?>
<!-- -->
<!DOCTYPE cross-domain-policy SYSTEM "">
    <allow-access-from domain="*" />
    <allow-http-request-headers-from domain="*" headers="*"/>
	<site-control permitted-cross-domain-policies="all"/>

But when hosted distantly, my default hosting provider configuration allowed crossdomain requests already so I had nothing to do :wink: . Have a look at this: