検索
ホームページphp教程php手册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.


声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

MantisBT

MantisBT

Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

SublimeText3 英語版

SublimeText3 英語版

推奨: Win バージョン、コードプロンプトをサポート!

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)