好吧我試圖訪問一些使用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