Archive for the ‘Web Services’ Category

Flex: testing/running php proxy locally

October 15, 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…………….

Advertisements

Country – Capital XML List using GeoNames

October 15, 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.