php curl headers do not return from website?

為{幸葍}努か 提交于 2019-12-01 09:33:15

First of all, the code you posted is valid. You don't need to alter it.

If you just try it with ex. https://www.google.com it works.

The problem is that your version of PHP uses LibreSSL for php-curl HTTPS connections.

I have the same issue on macOS where my version of PHP uses OpenTransport.

The website you're connecting to requires to establish a SSL connection in a way that LibreSSL is not able to handle.

You need to compile/install OpenSSL and run your code on a PHP interpreter that has been compiled to use it for php-curl.


Update:

as you're on macOS you may compile PHP from source. Googling for macos compile php from source will return a list of "recipes" to do that.

If you use brew to compile PHP (and all the "web applications stack") you may take a look here:

osx 10.10 Curl POST to HTTPS url gives SSLRead() error

The question (and answer) also address a problem similar to the one in your question.

I think that is not your problem. I think they block something when it's requested over PHP. When you use file_get_contents you get the following output.

Warning: file_get_contents(): SSL: Operation timed out in /test.php on line 2
Warning: file_get_contents(https://www.gearbest.com/mobile-phones/pp_1686789.html?wid=1817324): failed to open stream: HTTP request failed!  in /test.php on line 2

When you use the following url in your script it's working fine (https://www.test.de).

I have made some other tests with your script but i get everytime a result and your excepted result.

Try adding the CURLOPT_SSL_VERIFYPEER option, it connects via SSl but checks the certificate, like this:

<?PHP
  $handle=curl_init('https://www.google.com');
  curl_setopt($handle, CURLOPT_VERBOSE, true);
  curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
  $content = curl_exec($handle);
  echo $content;
?>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!