好吧我试图访问一些使用PHP代理的JSON,因为我被告知是在不控制网站策略时进行跨域访问的唯一方法。PHP代理服务器和调用JSON?
这里是下面的代码,我想通过一个老乡计算器用户共享一个PHP代理使用方法:
function curl_download($Url){
// is cURL installed yet?
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
// OK cool - then let's create a new cURL resource handle
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $Url);
// Set a referer
curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
// User agent
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
return $output;
}
问题是,当我更换http://www.nfl.com/liveupdate/scorestrip/ss.json没什么$ URL似乎发生。我不确定如何使用这个PHP代理,虽然我从来没有做过这种类型的事情。
我想创建一个单独的PHP文件,然后发送请求到此代码?我真的很想在这里做什么,以便我可以从上面的网站访问json。
这似乎输出:警告:不能更改头信息 - 头已经发出(输出开始在C:\的Inetpub \虚拟主机\ allencoded。 com \ httpdocs \ test.php:12)在第88行的C:\ inetpub \ vhosts \ allencoded.com \ httpdocs \ test.php中警告:无法修改标头信息 - 已经发送的标头(输出开始于C:\ inetpub \ vhosts \ allencoded.com \ httpdocs \ test.php:12)在C:\ inetpub \ vhosts \ allencoded.com \ httpdocs \ test.php在线88警告:无法修改标题信息 - 已经发送的标题(输出从C开始:\ inetpub \ vhosts \ allencoded.com \ httpdocs \ test.php:12)in – allencoded