URLに関するphp.netのすべての例は、httpのみでdemostratedであり、httpsではdemostratedではありません。なぜこれがhttpsで実証されなかったのか、私は本当に分かりません。 file_get_contentsはhttp URLに対してtrueを返し、https URLに対してfalseを返します。httpsを使用したPHPのfile_get_contentsパラメータはfalseを返します
- この機能が実行されているサーバーで何かを有効にする必要がありますか?
- 私はそれが論理的なエラーだが、この論理的なエラーは組み込み関数で起こっていることを認識しています。文法上の誤りはありません。私はここで何が欠けていますか?
- 私の予想される出力は、
true
から返され、https urlが渡されたときにfile_get_contentsから戻ります。
コード:
function connectMe() {
$urlHeader = $_REQUEST['urlHeader'];
// if this is a http url it's working for file_get_contents returns true
// if this is a https url it's not working file_get_contents gives false
$status = send($urlHeader);
var_dump($status);
echo $status ? 'success' : 'failed';
exit;
}
function send($url) {
$ctx = stream_context_create(
array(
'http'=>array(
'header'=>"Content-type: application/x-www-form-urlencoded",
'method'=>'POST',
'content'=>NULL
)
)
);
var_dump(stream_get_wrappers());
$w = stream_get_wrappers();
echo 'openssl: ', extension_loaded ('openssl') ? 'yes':'no', "\n";
echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n";
echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n";
echo 'wrappers: ', var_export($w);
return file_get_contents($url, 0, $ctx);
}
注 1.上記のコードは何も結果に変化しないstackoverflowので与え溶液当たりとして統合されています。 2. openssl
が有効で、allow_url_fopen
がオンです。私が取得
OUTPUT:
アレイ(9){[0] =>列(5) "HTTPS" [1] =>列(4) "FTPS" [2] =>列(3 (4) "glob" [5] =>文字列(4) "データ" [6] =>文字列(4) "文字列(4) (4) "phar"}
openssl:はいhttpラッパー:はいhttpsラッパー:はいラッパー:配列(0 => ' ftp '、' = '' ftp '、2 =>' php '、3 =>'ファイル '、4 =>' glob '、5 =>'データ '、6 =>' http '、7 =>' ftp '、8 =>' phar ')
警告:file_get_contents():php_network_getaddresses:gethostbyname failed。 40行目のFILENAME.PHPのerrno = 0
警告:file_get_contents(https://someIPhereまたはウェブサイト):ストリームのオープンに失敗しました:php_network_getaddresses:gethostbyname failed。ライン上のFILENAME.PHPでのerrno = 0(偽)40
ブール値
は確かです '$ _REQUEST( 'urlHeaderは');'正しいですか? '$ _REQUEST'は関数ではありません – apokryfos
多分この[リンク](https://stackoverflow.com/questions/1975461/how-to-get-file-get-contents-to-work-with-https)は助けることができます –
HTTPSでファイル\ _get \ _contents()を動作させるにはどうすればいいですか?](https://stackoverflow.com/questions/1975461/how-to-get-file-get-contents-to-work-with) -https) –