I have been playing with Flex a bit, to write an Flash application for my masters degree (I find the flex environment much better for programming than flash), and like most people working with flash I have come up against the cross domain issue (where the player won’t pull data from a domain which doesn’t have a cross domain policy allowing them to do so). This is a problem for the application I am working with, because I want to pull RSS feeds.

The obvious answer, a php proxy. In a way that makes it sound grander than it is because all it really is is a script to pull data from a remote source to get around the cross domain issue.

here is the script (simplified):

<?php
	header("Content-Type: application/xml; charset=UTF-8");
	$url = $_GET['url'];
	readfile($url);
?>

Now the code pulls back the feed as expected, but prepends this:

67c0

immediately before the content. Where does that come from, any ideas? Wherever it comes from it obviously means the feed won’t parse!

In the end, I used curl like this (simplified):

<?php
	header("Content-Type: application/xml; charset=UTF-8");

	// note that this will not follow redirects

	$url = $_GET['url'];

	// create a new curl resource
	$ch = curl_init();

	// set URL and other appropriate options
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, 0);

	// grab URL and pass it to the browser
	curl_exec($ch);

	// close curl resource, and free up system resources
	curl_close($ch);
?>

Technorati Tags:
, , , ,