Get Firefox!

Valid HTML 4.01 Transitional

Home > Programming > Post JSON Data from Adobe / Apache Flex

How to Post JSON data from Adobe / Apache Flex

To save you some time and sanity, here is how you post JSON data to a rest service from Flex.

	var jsonRequest:String = JSON.stringify(exampleObject);

	var s:HTTPService = new HTTPService(); 
	s.url = "http://example.org/rest/service";
	s.contentType = "application/json";
	s.resultFormat = mx.rpc.http.HTTPService.RESULT_FORMAT_TEXT;
	s.method = "POST";
	s.useProxy = false;
	s.addEventListener("result", handleComplete);
	s.addEventListener("fault", handleError);
	s.send(jsonRequest);

	function handleComplete(data:String):void { }
        function handleError(fault:Event):void { }
    
Pulling in data with GET is much the same.

MATE Framework

If you can come up with a way to do the above purely using MATE let me know. I could not get the HTTPServiceInvoker to include the JSON payload and ended up creating a method based on the above called from an InlineInvoker in the event map mxml.