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