PHP script works fine until I send a parameter from HTTPService in Flash Builder 4?

Posted by ben on Stack Overflow See other posts from Stack Overflow or by ben
Published on 2010-05-10T03:33:06Z Indexed on 2010/05/10 3:38 UTC
Read the original article Hit count: 459

Filed under:
|
|
|
|

I'm using a PHP script to read an RSS feed in my Flex 4 app. The script works when I put the url of the feed in the actual script, but I can't get it to work when I try to send the URL as a parameter from a HTTPService in Flex. Can anyone tell me what I'm doing wrong?

Here is the HTTPService from Flex 4 that I'm using:

<mx:HTTPService url="http://talk.6te.net/proxy.php"
          id="proxyService" method="POST" 
          result="rssResult()" fault="rssFault()">
 <mx:request>
  <url>
       http://feeds.feedburner.com/nah_right
  </url>
 </mx:request>
</mx:HTTPService>

This is the script that works:

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

curl_setopt($ch, CURLOPT_URL, "http://feeds.feedburner.com/nah_right");
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;
}
?>

But this is what I actually want to use, but it doesn't work:

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

curl_setopt($ch, CURLOPT_URL, $_REQUEST['url']);
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;
}
?>

Here is the request and response output of the HTTPService from the network monitor in Flash Builder 4 (using the PHP script that doesn't work):

Request:

POST /proxy.php HTTP/1.1
Host: talk.6te.net
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Content-type: application/x-www-form-urlencoded
Content-length: 97

url=%0A%09%09%09%09%09http%3A%2F%2Ffeeds%2Efeedburner%2Ecom%2Fnah%5Fright%0A%20%20%20%20%09%09%09

Response:

HTTP/1.1 200 OK
Date: Mon, 10 May 2010 03:23:27 GMT
Server: Apache
X-Powered-By: PHP/5.2.13
Content-Length: 15
Content-Type: text/html

<url> malformed

I've tried putting the URL in " " in the HTTPService, but that didn't do anything. Any help would be greatly appreciated!

© Stack Overflow or respective owner

Related posts about php

Related posts about php5