Hello. I have a new blog.

I've moved this blog to the following URL Kerkness.ca. Thank you for visiting, please update your bookmarks.

Wednesday, February 27, 2008

Use a remote HTTPService in Flex with a PHP Proxy

One way to get around the hassle of a common security error when trying to call a HTTPService running on a different domain than your Flex application is to use a simple and local PHP script as a proxy to call the HTTPService for you. Perhaps not a solution you would want to use if you need to load massive piles of data but in most cases it works just fine and takes seconds to set up.

proxy.php

$content = file_get_contents(str_replace(' ','%20',$_GET['url']));
if ($content !== false) {
echo($content);
} else {
// there was an error
}

HTTPService in MXML
<mx:HTTPService id="myService"
url="http://www.localdomain.com/proxy.php?url=http://www.remote.com/api"/>

1 comment:

  1. muchas gracias por el código.
    Es la solución más simple que he econtrado en la red y lo que primero me funcionó.

    Saludos

    ReplyDelete

Thank you for the comments.