file_get_contents 无法读取https的问题解决!

2019-03-02 01:05|来源: 网路

做微信公众平台开发,要通过读取公众平台的一个网址实时获得access_token,用了file_get_contents 在本地测试一切正常,但在服务器上却返回空数据。经过网上查资料原来要修改php.ini中的一个默认配置:

1.windows下的PHP,只需要到php.ini中把extension=php_openssl.dll前面的;删掉,重启服务就可以了。
2.linux下的PHP,就必须安装openssl模块,安装好了以后就可以访问了。
3.如果服务器你不能修改配置的话,那么就使用curl函数来替代file_get_contents函数,当然不是简单的替换啊。还有相应的参数配置才能正常使用curl函数。

我的是windows服务器,修改后,OK!


转自:http://www.cnblogs.com/finary/p/3322891

相关问答

更多
  • 如果URL正确,您应该已经获得纯XML。 如果遇到问题,可能是该网址希望您登录或者有类似的东西。 使用var_dump($ str),然后查看该页面上的源代码,以查看返回的内容。 无论哪种方式,从XML获取任何链接内容都没有什么神奇的方法。 所有你会得到的是XML本身,并需要更多的PHP代码来处理和获取它的任何链接/图像/数据。 You should already be getting the pure XML if the URL is correct. If you're having trouble ...
  • 尝试以下脚本来查看是否有可用于PHP脚本的https包装器。 $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" ...
  • 修复。 我将端口添加到url正在使用的iptables,因为它不是“正常”端口并重新启动我的防火墙并且工作正常。 谢谢。 Fixed it. I added the port to the iptables that the url is using, as it's not an "normal" port and restarted my firewall and worked perfectly. Thank you.
  • 在将字符串提交给file_get_contents之前,请尝试对字符串进行trim()。 可能是变量中有空格字符,并且正在提交和解释为URL的一部分。 Try to us trim() on the string before you submit it to file_get_contents. It may be that a whitespace character is in the variable and is being submitted and interpreted as part of ...
  • 我没有看到代码有任何问题,配对 - 它在我的设置上本地运行正常,我可以获取文件,并可以做任何我喜欢的事情。 试试它在不同的主机上运行 - 可能是你的php.ini搞砸了并且搞乱了脚本..或者你可能遇到了其他一些源的问题..可能是你分享了整个文件源,或至少更大的一部分.. 干杯! I don't see anything wrong with the code, mate - it runs fine locally on my setup and I can get the file, and can do ...
  • 你的file_get_contents将返回字符串JSON。 所以你需要先解析它。 $link = "https://stream.live/-/streams/users/kawkaw?includeTrending=true"; $actualLink = file_get_contents($link); $actualJson = json_decode($actualLink); echo $actualJson->trendingStreams[0]->hlsUrl; Your file_ge ...
  • Lumen没有你在Laravel中熟悉的public_path()来轻松获取公共文件的路径。 重新实现它的最简单方法是在项目中添加一个名为irazasyed / larasupport的包,它会添加各种丢失的帮助程序(包括public_path() )以及添加Lumen中缺少的vendor publish命令。 或者,如果您不想添加第三方软件包,只需在您的app目录中创建一个名为helpers.php文件,然后在您的composer.json文件中在“autoload”部分中添加以下内容并运行compose ...
  • 你需要使用m或Multiline标志。参见演示。 https://regex101.com/r/cT0hV4/12 $re = "/^\\w+:/m"; $str = "From: elvis@tabloid.org (The King)\nSubject: be seein' ya around\nDate: Mon, 23 Oct 2006 11:04:13\nFrom: The Prez \nDate: Wed, 25 Oct 2006 8:36: ...
  • 如果要从远程系统加载文件,则应该使用curl。 file_get_contents不处理网络延迟,重定向或错误捕获。 并且显然在服务器配置中禁用。 If you are loading a file from a remote system, you should be using curl instead. file_get_contents doesn't handle network delays, redirects or error capture. And is obviously disabl ...
  • 你可能面临的最小问题始终是最困难的问题。 为了将来参考,请始终打开错误报告,以便您可以选择这样的错误。 ini_set('display_errors', 1); error_reporting(-1); 这导致了您的错误,这意味着您在定义$a变量之前错过了一个分号( ; )。 It's always the tiny little issues that you could face that are the hardest ones. For future reference while develo ...