file_get_contents(): SSL operation failed with code 1, Failed to enable crypto

前端 未结 16 1919
情歌与酒
情歌与酒 2020-11-22 04:31

I’ve been trying to access this particular REST service from a PHP page I’ve created on our server. I narrowed the problem down to these two lines. So my PHP page looks li

16条回答
  •  一整个雨季
    2020-11-22 05:01

    You can get around this problem by writing a custom function that uses curl, as in:

    function file_get_contents_curl( $url ) {
    
      $ch = curl_init();
    
      curl_setopt( $ch, CURLOPT_AUTOREFERER, TRUE );
      curl_setopt( $ch, CURLOPT_HEADER, 0 );
      curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
      curl_setopt( $ch, CURLOPT_URL, $url );
      curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, TRUE );
    
      $data = curl_exec( $ch );
      curl_close( $ch );
    
      return $data;
    
    }
    

    Then just use file_get_contents_curl instead of file_get_contents whenever you're calling a url that begins with https.

提交回复
热议问题