file_get_contents(url): failed to open stream的解决方案
www.2cto.com:摘自英文网站
提问者:
Hello Everyone;
I am having a php file that gets the contents from a URL, i am getting the failure message
Collapse | Copy CodeWarning: file_get_contents(http://xxxxxx): failed to open stream: HTTP request failed! in xxxx.php on line xx
i tried so many online solutions but its still not working. here is the code
Collapse | Copy Code $cryptpass = rawurlencode(crypt($pc['pcpassword']));
$url = "http://" . $pc['pcname']."/Reports/ReportList.php?&username={$pc['pcusername']}&cryptpass=$cryptpass&noredir=1";
$parsed_list = read_general_list($url, false);
Collapse | Copy Codefunction read_general_list($url, $make_assoc = false)
{
$compressed_data = file_get_contents($url);
}
$compressed_data is always null and it throws an error:
Warning: file_get_contents(http://xxxxxx): failed to open stream: HTTP request failed! in xxxx.php on line xx
Any suggestions please?
答复:
I am sorry, i never updated this question completely. May be if some one is still looking for an answer.
This has worked for me. This is the equivalent function for File_get_contents, but can handle large amount of data. I found this solution online.
Collapse | Copy Code function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
第二个解答:
As the error message says, the stream (URL) requested cannot be opened. There are many possible reasons for this:
1. base URL is bad. $pc['pcname']
2. username and/or password are bad
3. username/password do not have permission on the server
4. Your system cannot reach the server (firewall, PHP permissions, ...)
4. ...
I would use the following strategy to debug:
1. Dump $url and write it down.
2. Use a browser with debug tools (eg Firefox/Firebug) and try to access that URL.
3. Look at the headers returned to see what error the server reports (if any).
4. Think about why that error is returned...
Cheers,
Peter
If this answers your question, vote and mark it accepted.

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Win11是微軟推出的最新作業系統,相較於先前的版本,Win11在介面設計和使用者體驗上有了很大的提升。然而,一些用戶反映他們在安裝Win11後遇到了無法安裝中文語言套件的問題,這就給他們在系統中使用中文帶來了困擾。本文將針對Win11無法安裝中文語言套件的問題提供一些解決方案,幫助使用者順利使用中文。首先,我們要明白為什麼無法安裝中文語言包。一般來說,Win11

scipy庫安裝失敗的原因及解決方案,需要具體程式碼範例在進行Python科學計算時,scipy是一個非常常用的函式庫,它提供了許多用於數值計算、最佳化、統計和訊號處理的功能。然而,在安裝scipy庫時,有時會遇到一些問題,導致安裝失敗。本文將探討scipy庫安裝失敗的主要原因,並提供對應的解決方案。安裝依賴套件失敗scipy庫依賴一些其他的Python庫,例如nu

標題:解決Oracle字元集修改造成亂碼問題的有效方案在Oracle資料庫中,當字元集被修改後,往往會因為資料中存在不相容的字元而導致亂碼問題的出現。為了解決這個問題,我們需要採取一些有效的方案來處理。本文將介紹一些解決Oracle字元集修改引起亂碼問題的具體方案和程式碼範例。一、匯出資料並重新設定字元集首先,我們可以透過使用expdp指令將資料庫中的資料匯出

報錯的原因NameResolutionError(self.host,self,e)frome是由urllib3函式庫中的例外類型,這個錯誤的原因是DNS解析失敗,也就是說,試圖解析的主機名稱或IP位址無法找到。這可能是由於輸入的URL位址不正確,或DNS伺服器暫時無法使用所導致的。如何解決解決此錯誤的方法可能有以下幾種:檢查輸入的URL地址是否正確,確保它是可訪問的確保DNS伺服器可用,您可以嘗試在命令行中使用"ping"命令來測試DNS伺服器是否可用嘗試使用IP位址而不是主機名稱來存取網站如果是在代理

OracleNVL函數常見問題及解決方案Oracle資料庫是廣泛使用的關係型資料庫系統,在資料處理過程中經常需要處理空值的情況。為了因應空值所帶來的問題,Oracle提供了NVL函數來處理空值。本文將介紹NVL函數的常見問題及解決方案,並提供具體的程式碼範例。問題一:NVL函式用法不當NVL函式的基本語法為:NVL(expr1,default_value)其

區別:1、定義不同,url是是統一資源定位符,而html是超文本標記語言;2、一個html中可以有很多個url,而一個url中只能存在一個html頁面;3、html指的是網頁,而url指的是網站位址。

C++中機器學習演算法面臨的常見挑戰包括記憶體管理、多執行緒、效能最佳化和可維護性。解決方案包括使用智慧指標、現代線程庫、SIMD指令和第三方庫,並遵循程式碼風格指南和使用自動化工具。實作案例展示如何利用Eigen函式庫實現線性迴歸演算法,有效地管理記憶體和使用高效能矩陣操作。

PyCharm是一款功能強大的Python整合開發環境,廣受開發者喜愛。然而,有時候我們在使用PyCharm時可能會遇到金鑰失效的問題,導致無法正常使用軟體。本文將為大家揭秘PyCharm密鑰失效的解決方案,並提供具體的程式碼範例,幫助讀者快速解決這個問題。在開始解決問題之前,我們首先要了解密鑰失效的原因。 PyCharm的金鑰失效通常是由於網路問題或軟體本身
