PHP 5 と cURL を使用して、wowarory.com から XML データを取得するスクリプトを作成しています。
$url = "http://www.wowarmory.com";
$userAgent = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12';
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$url);
$str = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
$str .= "Accept-Language: en-us,en;q=0.5\r\n";
$str .= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
$str .= "Keep-Alive: 300\r\n";
$str .= "Connection: keep-alive\r\n";
curl_setopt($ch, CURLOPT_HTTPHEADER, array($str));
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 3000);
$xml = curl_exec($ch);
ホストされている Web サーバーからこれを実行すると、期待どおりの XML 応答が得られます。しかし、localhost Web サーバーから実行すると、何も得られません。
localhost (yahoo.com、さらには worldofwarcraft.com ) から cURL を介して他の Web サイトを取得できますが、wowarmory.com は取得できません。したがって、cURL が適切に機能していることはわかっています。
次のバージョンの PHP と cURL を使用しています。
ホストされたサーバー:
- PHP 5.2.6
- cURL libcurl/7.16.1 OpenSSL/0.9.7e zlib/1.2.3
ローカルホスト:
- PHP 5.2.6
- cURL libcurl/7.16.0 OpenSSL/0.9.8i zlib/1.2.3
何か案は?
編集: localhost は Windows XP SP3 を実行しています。Web ブラウザから wowarmory.com にアクセスできます。Tracert はホップ 13 でタイムアウトを開始します (明らかに、私の場所から):
13 458 ms 529 ms 549 ms 0.so-6-0-0.BR1.LAX15.ALTER.NET [152.63.116.21]
14 476 ms 510 ms 488 ms 192.205.34.29
15 257 ms 279 ms 261 ms cr1.la2ca.ip.att.net [12.122.128.14]
16 242 ms 259 ms 249 ms gar5.la2ca.ip.att.net [12.122.128.25]
17 252 ms * 1691 ms 12.122.255.74
18 * 2361 ms 634 ms mdf001c7613r0003-gig-10-1.lax1.attens.net [12.129.193.242]
19 * * * Request timed out.
残念ながら、tcptraceroute には詳しくありません。
curl の Windows バイナリ バージョンは、http://www.wowarory.com/ に対しては何も返しませんが、http: //www.yahoo.com/ に対しては返します。
wget がありません。
編集 2: ローカルホストの Web サイトに問題なくアクセスできます。それは、私が受け取っていないcurlからの応答です。私はほとんどデフォルトのXAMPPインストールを実行しています(Windows XPのapache 2)。これはすべて正常に機能します。