gpt4 book ai didi

php - "SSLRead() return error -9806"当我尝试在 https 上使用 cURL

转载 作者:行者123 更新时间:2023-12-03 19:50:11 25 4
gpt4 key购买 nike

我正在尝试通过 cURL 获取站点的内容,它在终端上工作得很好,但是它不适用于 PHP,下面是我的代码。

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://example.com/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"referer: https://www.example.com/something",
"user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Firefox/52.0"
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}

我已经尝试了 this question 上的答案, 但它对我不起作用,我得到了同样的错误..

我也试过在我的代码中包含下面的设置,它也没有用。

  CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,

我正在使用 Nginx 和 Laravel,我的 PHP 版本是 7.1.2,我的 cURL 版本是 7.51.0,我在 macOS Sierra 10.12.3.

我怎样才能让它工作?

最佳答案

重新安装支持 OpenSSL 的 curl。如果您使用 Homebrew :

brew remove curl
brew install openssl
brew install --with-openssl curl

关于php - "SSLRead() return error -9806"当我尝试在 https 上使用 cURL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42964546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com