Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法对来自我的服务器(php)的特定url使用file_get_contents()_Php_File_Api_Get - Fatal编程技术网

无法对来自我的服务器(php)的特定url使用file_get_contents()

无法对来自我的服务器(php)的特定url使用file_get_contents(),php,file,api,get,Php,File,Api,Get,所以我向一个url发出get请求,一个https://地址,我只想从中接收一个小文本。这在localhost上运行良好,但当我在我的web服务器(由one.com托管)上运行时,它就不起作用了。它显示了这个错误: Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14077458:SSL routines:SSL23_GET_SERVER_HELLO:re

所以我向一个url发出get请求,一个https://地址,我只想从中接收一个小文本。这在localhost上运行良好,但当我在我的web服务器(由one.com托管)上运行时,它就不起作用了。它显示了这个错误:

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: 
 error:14077458:SSL routines:SSL23_GET_SERVER_HELLO:reason(1112) in 
 /customers/0/4/f/mydomain.se/httpd.www/test.php on line 4 Warning: 
 file_get_contents(): Failed to enable crypto in 
 /customers/0/4/f/mydomain.se/httpd.www/test.php on line 4 Warning: 
 file_get_contents(https://dogeapi.com/wow/?
 api_key={my apikey}&a=get_new_address&address_label=46): failed to open 
 stream: operation failed in /customers/0/4/f/mydomain.se/httpd.www/test.php on line 4

我可以从web服务器发出其他get请求,但不是这个特定的请求。原因可能是什么?

最好的解决方法是使用cURL

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSLVERSION, 3); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);

var_dump( $result ); // will contain raw return

最重要的一条线是SSLVERSION。在curl调用的构造上,您的里程可能会有所不同,但我以前遇到过这种情况,从file\u get\u contents或任何PHP流移动到curl就是解决方案。

最有可能的是某个损坏的ssl库?你能从那里的命令行
wget
找到url吗?文件\u get\u contents()不应该用于https连接,它工作了!请求是否会存储在变量$result中?因为它似乎是一个布尔值。我想从网站上获取一个变量中的文本,可能吗?如果你想要转入$result,只需添加CURLOPT_RETURNTRANSFERAnd,很高兴它帮助了你:)我真的不明白,生词和其他东西,从来没有听说过curl。。如果我希望从网站请求的文本包含在一个变量中,我该怎么做?ELI5Edited,请注意细微的区别:)为您添加了curl_setopt调用,它调整了curl处理程序的工作方式,并插入了一个var转储,以便您可以查看服务器返回的内容。