file_get_contents (URL): failed to open stream Solution _php Tutorial

Source: Internet
Author: User
Www.2cto.com: from the English website

Asked by:
Hello Everyone; I am have 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 it 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);} $compresse D_data is always null and it throws a Error:Warning:file_get_contents (HTTP://XXXXXX): Failed to open stream:http Reque St failed! In xxxx.php on line xx any suggestions?

Reply:

I am sorry, I never updated this question completely. May be if some one are still looking for an answer. This have worked for me. 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 is many possible reasons for this:1. The base URL is the bad. $pc [' Pcname ']2. Username and/or password is bad3. Username/password do not has 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 this URL.3. Look at the headers returned to see what error the server reports (if any). 4. Think about why this error is returned ... Cheers,peter If This answers your question, vote and mark it accepted.

http://www.bkjia.com/PHPjc/477853.html www.bkjia.com true http://www.bkjia.com/PHPjc/477853.html techarticle www.2cto.com: From the English web site questioner: Hello Everyone; I am have a php file that gets the contents from a URL, I am getting the failure message Collapse | Copy codewarning ...

  • 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.