Archive for October, 2010

Flex: testing/running php proxy locally

Friday, October 15th, 2010

When accessing URL’s through HttpServices from a remote domain, it often works fine on the local system but fails to connect when the swf is uploaded to the web (google searh ‘flex crossdomain.xml proxy’).

A common way around this is to place a PHP file on your web server that acts as a go-between for the remote site and the swf (an example discussed on Dennis Jaamaan’s site, with proxy code).

This article explains how to setup a local PHP server, and test your PHP proxy locally through Flex Builder 3

1. Download a PHP server: http://www.wampserver.com/en/download.php

2. Install it, leaving whatever default settings it suggests.

3. Click the WampServer taskbar icon, and go to PHP/PHP_extensions/ and click php_curl (need to enable this to use the example below). Then click Start All Services & Put Online.

4. Create a php file named flexProxy.php and put in the code below:

< ?php
$ch = curl_init();
$timeout = 30;
$userAgent = $_SERVER['HTTP_USER_AGENT'];

$url = $_REQUEST['url'];
$place = $_REQUEST['place'];

$fullGoogleWeatherPath = $url . $place;

curl_setopt($ch, CURLOPT_URL,$fullGoogleWeatherPath);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo curl_error($ch);
} else {
    curl_close($ch);
    echo $response;
}
?>

5. Save this file and put it in the localhost directory: C:\wamp\www\

Read the rest of this article…………….

Country – Capital XML List using GeoNames

Friday, October 15th, 2010

Was looking around trying to find an XML file of countries and capital cities.

Initially came accross some rather incomplete xml files with the ISO two digit country codes, but so far the best info I found is from GeoNames.

If your using Flash/Flex, it doesnt matter that their crossdomain.xml is outdated, because they use REST web services.

e.g.  http://ws.geonames.org/countryInfo?

In flex, you can use a HttpService to specify request attributes, good example here. Very handy.

Flex web service, WSDL crossdomain.xml

Friday, October 15th, 2010

If you’re building a Flex web app utilising wsdl webservices, dont bother using www.webservicex.net services, they hav’nt updated their crossdomain.xml file to include the necessary Flash 9/10 XML elements. Any web service calls will result in a URL FaultEvent error. I have contacted them, so hopefully they will update it. The crossdomain.xml file (of your site as well) should contain the following element:

<allow-http-request-headers-from domain="*" headers="*" />

Go to any sites root address to check it out e.g.  http://www.xignite.com/crossdomain.xml