我正在使用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中,但沒有做任何事情。任何幫助將不勝感激!
非常感謝你,這工作完美! – ben 2010-05-10 05:25:58