2010-05-10 65 views
0

我正在使用PHP脚本在我的Flex 4应用程序中读取RSS提要。当我将Feed的URL放入实际脚本中时,该脚本正常工作,但当我尝试从Flex中的HTTPService发送URL作为参数时,我无法使其工作。PHP脚本正常工作,直到我从Flash Builder 4中的HTTPService发送参数为止?

下面是我使用的Flex从4 HTTPService在:

<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> 

这是作品的脚本:

<?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; 
} 
?> 

但是,这是我真正想用,但它不工作(只有第6行不同):

<?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; 
} 
?> 

这里是HTTPService的请求和响应输出从第在Flash Builder 4 e网显示器(使用PHP脚本,不工作):

请求:

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 

响应:

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 

我试图把网址中的“ “在HTTPService中,但没有做任何事情。任何帮助将不胜感激!

回答

1

$ _REQUEST ['url']的值是urlencoded,而不是urlencoding,只是查询字符串。您的代码和/或FLEX服务中的某处会导致“双重urlencode”。只需url解码它,你应该得到你需要的价值。另外,我注意到换行符和制表符,所以您可能也要修剪它。

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

curl_setopt($ CH,CURLOPT_URL,修剪(urldecode($ _ 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; 
} 
?> 

就是这样。

+0

非常感谢你,这工作完美! – ben 2010-05-10 05:25:58

相关问题