2017-10-12 1 views
1

URLに関するphp.netのすべての例は、httpのみでdemostratedであり、httpsではdemostratedではありません。なぜこれがhttpsで実証されなかったのか、私は本当に分かりません。 file_get_contentsはhttp URLに対してtrueを返し、https URLに対してfalseを返します。httpsを使用したPHPのfile_get_contentsパラメータはfalseを返します

  1. この機能が実行されているサーバーで何かを有効にする必要がありますか?
  2. 私はそれが論理的なエラーだが、この論理的なエラーは組み込み関数で起こっていることを認識しています。文法上の誤りはありません。私はここで何が欠けていますか?
  3. 私の予想される出力は、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

ブール値

+4

は確かです '$ _REQUEST( 'urlHeaderは');'正しいですか? '$ _REQUEST'は関数ではありません – apokryfos

+2

多分この[リンク](https://stackoverflow.com/questions/1975461/how-to-get-file-get-contents-to-work-with-https)は助けることができます –

+1

HTTPSでファイル\ _get \ _contents()を動作させるにはどうすればいいですか?](https://stackoverflow.com/questions/1975461/how-to-get-file-get-contents-to-work-with) -https) –

答えて

0

チャンスはあなたが自己署名SSLを指しているかもしれないということです失敗しました。もしそうなら、それが理由かもしれません。 URLに有効なSSL証明書があることを確認してください。

SSL検証をバイパスしたい場合は、 'verify_peer' = falseを設定するためにstream_context_createを追加する必要があります。

は、以下を参照してくださいfile_get_contents(): SSL operation failed with code 1 (certificate verify failed)

+1

...元の質問を重複して再度作成する:) – CD001

関連する問題