PHP file_get_contents强制调用http而不是https

问题描述 投票:0回答:1

我的一个网站发生了一个奇怪的错误。

我正在使用file_get_contents包装器对API进行HTTPS调用(在此示例中被截断),如下所示:

$url = 'https://svcs.ebay.com/services/search/FindingService/v1....';
$f = file_get_contents($url);

很简单,对吧?但是,这是一个很奇怪的部分,我在日志中不断显示以下错误:

PHP Warning:  file_get_contents(http://svcs.ebay.com/services/search/FindingService/v1?....)

任何想法为何会尝试将我的代码中的https请求强制降低为http?我忽略的任何事情都会导致此问题?

php file-get-contents
1个回答
-1
投票
您无法通过file_get_content发出https请求。您应该使用curl库。您可以尝试以下方法:

function file_get_content_curl ($Url) { if (!function_exists('curl_init')){ die('CURL is not installed!'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $Url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); curl_close($ch); return $output; }

© www.soinside.com 2019 - 2024. All rights reserved.