使用 cURL 和 PHP 检索 iTunes App Store XML [英] Retrieving iTunes App Store XML with cURL and PHP
问题描述
过去几周我一直在使用我找到并修改过的脚本从 iTunes App Store 中提取信息.一切正常,直到几天前我意识到不再生成 XML 时.这是生成 XML 的脚本的代码:
I have been extracting information from the iTunes App Store for the past couple of weeks using a script I found and modified. Everything was working fine until a couple days ago when I realized that no XML was being generated anymore. Here is the code for the script that generates the XML:
<?php
header("Content-type: text/plain");
ini_set('display_errors', false);
if(isset($_GET['appID']))
{
$appID = (int)stripslashes($_GET['appID']);
$url = "http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=" . $appID . "&mt=8";
$useragent = "iTunes/9.0.2 (Macintosh; Intel Mac OS X 10.5.8) AppleWebKit/531.21.8";
$header = array("X-Apple-Store-Front: 143441-1");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
}
?>
所以我添加了 HTTPHEADER 选项无济于事,但更重要的是,当我进入终端并输入以下内容时,它运行得非常好:
So I added the HTTPHEADER option to no avail, but the kicker is that it works perfectly well when I go to Terminal and type this:
curl -s -A "iTunes/9.0.2 (Macintosh; Intel Mac OS X 10.5.8) AppleWebKit/531.21.8" -H "X-Apple-Store-Front: 143441-1" 'http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=339038562&mt=8'
它返回我需要的 XML,但为什么 PHP 脚本不起作用?
It returns the XML that I need, but why won't the PHP script work?
感谢任何帮助!
推荐答案
对我来说效果很好.以下是一些需要考虑的事项:
Works fine for me. Here are few things to think about:
- 您确定设置了
$GET['appID']
吗?也许脚本是通过 POST 运行的? - 注释掉
ini_set('display_errors', false);
并查看是否出现任何通知/警告/错误. - 脚本是否与 curl 命令行在同一个盒子上运行?
- Are you sure
$GET['appID']
is set? Perhaps the script is being run via a POST? - Comment out
ini_set('display_errors', false);
and see if any notices/warnings/errors appear. - Is the script running on the same box as the curl command line?
这篇关于使用 cURL 和 PHP 检索 iTunes App Store XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!