0

我正在使用 PHP 脚本来读取我的 Flex 4 应用程序中的 RSS 提要。当我将提要的 URL 放入实际脚本中时,该脚本有效,但是当我尝试从 Flex 中的 HTTPService 将 URL 作为参数发送时,我无法让它工作。

这是我正在使用的 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;
}
?>

这是来自 Flash Builder 4 中网络监视器的 HTTPService 的请求和响应输出(使用不起作用的 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

我尝试将 URL 放在 HTTPService 中的“”中,但这并没有做任何事情。任何帮助将不胜感激!

4

1 回答 1

1

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

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

curl_setopt($ch, CURLOPT_URL, trim(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;
}
?>

就是这样。

于 2010-05-10T05:05:01.623 回答