file_get_contents(url): failed to open stream的解決方案_PHP教程

來源:互聯網
上載者:User
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 bad3. username/password do not have permission on the server4. 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.

http://www.bkjia.com/PHPjc/477853.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/477853.htmlTechArticlewww.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...

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.