File_get_contents (url): failed to open stream Solution

Source: Internet
Author: User

Www.2cto.com: from an English website

Questioner:
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 far 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?

Reply:

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;} second answer:
As the error message says, the stream (URL) requested cannot be opened. there are invalid 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 wocould 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.