Sunday, October 11, 2009

Flex and PHP POST

I always forget the syntax when trying to get around the Flex sandbox and use PHP. On the Flex side we need the following:

[Bindable]private var pr_url:String;

..
private function init():void
{
..
pr_url = "url to SOAP service for example";
pr.send();
}

..

<mx:HTTPService id="pr" resultFormat="e4x" result="getMonths_result(event);" fault="getMonths_fault(event);" method="POST" url="http://www.flexmappers.com/puertorico/test.php">
<mx:request xmlns="">
<url>
{pr_url}
</url>
</mx:request>
</mx:HTTPService>

On the PHP side:

<?php

header('Content-Type: text/xml');
$url = $_POST["url"];

$data = file_get_contents($url);
echo $data;
?>

No comments: