0

PHPスクリプトを使用してFlex4アプリでRSSフィードを読み取っています。フィードのURLを実際のスクリプトに入れるとスクリプトは機能しますが、FlexのHTTPServiceからパラメーターとしてURLを送信しようとすると機能しません。

これが私が使用しているFlex4の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

HTTPServiceの""にURLを入れてみましたが、何もしませんでした。どんな助けでも大歓迎です!

4

1 に答える 1

1

$_REQUEST['url'] 値は、クエリ文字列だけを URL エンコードするのではなく、URL エンコードされています。コードや 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 に答える