2013-09-26 30 views
2

我有一個website(PHP)託管在雅虎的小企業和application(爪哇)託管在Rackspace。PHP的'file_get_contents'不能從服務器工作

我正在做一個file_get_contents從網站到應用程序。在我的本地工作正常。但是當我在服務器上部署它之後嘗試相同的操作不起作用。

在這裏,我正在發送JSON格式的培訓列表的請求。

PHP部分

$trainingArrayJson = file_get_contents('http://mywebapplication.com/publicTraining/getTrainingsAsJson/'); 
$trainingArray = json_decode($trainingArrayJson); 
     ------- 
     ----- 

這是行不通的。

,如果我做

$trainingArrayJson = file_get_contents('http://localhost:8080/publicTraining/getTrainingsAsJson/'); 
$trainingArray = json_decode($trainingArrayJson); 

能正常工作。

+0

參考鏈接http://stackoverflow.com/questions/7794604/file-get-contents-not-working –

回答

1

如果fopen包裝已啓用,則可以使用此URL作爲文件名。有關如何指定文件名的更多詳細信息,請參閱fopen()。請參閱支持的協議和包裝以獲取有關各種包裝具有哪些功能的信息的鏈接,關於它們的用法的註釋以及它們可能提供的任何預定義變量的信息。

+0

去這個頁面,你將許多不同的組合,這可能會幫助你,HTTP: //php.net/manual/en/function.file-get-contents.php –

3

你需要讓

allow_url_fopen 

在php.ini配置文件。有些主機爲了安全而禁止它。

相關問題