在您的详细信息链接之后,异常消息显示:
cURL 错误 60:参见http://curl.haxx.se/libcurl/c/libcurl-errors.html
抬头看http://curl.haxx.se/libcurl/c/libcurl-errors.html I found
CURLE_SSL_CACERT (60)
对等证书无法使用已知的 CA 证书进行身份验证。
因此,这很可能是 SSL 验证/CA 捆绑包的问题。通过设置verify请求选项false
,guzzle(或curl)不会尝试根据证书验证主机,因此错误消失(--回复https://stackoverflow.com/a/28582692/413531)
但是,您不想这样做;) 相反,您应该尝试通过提供有效的 CA 捆绑包来解决该问题。
IIRC,在 v4 guzzle 中提供了默认证书(请参阅https://github.com/guzzle/guzzle/blob/4.2.3/src/cacert.pem),但在版本 5 中删除了它,现在尝试发现您的默认系统 CA 捆绑包。从the docs,检查这些位置:
Check if openssl.cafile is set in your php.ini file.
Check if curl.cainfo is set in your php.ini file.
Check if /etc/pki/tls/certs/ca-bundle.crt exists (Red Hat, CentOS, Fedora; provided by the ca-certificates package)
Check if /etc/ssl/certs/ca-certificates.crt exists (Ubuntu, Debian; provided by the ca-certificates package)
Check if /usr/local/share/certs/ca-root-nss.crt exists (FreeBSD; provided by the ca_root_nss package)
Check if /usr/local/etc/openssl/cert.pem (OS X; provided by homebrew)
Check if C:\windows\system32\curl-ca-bundle.crt exists (Windows)
Check if C:\windows\curl-ca-bundle.crt exists (Windows)
但是,我发现在创建新的证书时显式设置证书更容易Client
。这意味着:
- 下载https://github.com/guzzle/guzzle/blob/4.2.3/src/cacert.pem或更好(因为较新)http://curl.haxx.se/ca/cacert.pem (see http://curl.haxx.se/docs/caextract.html)
- 使用此证书的本地路径
Client
实例化
示例(假设您有名为cacert.pem
位于与脚本相同的目录中):
$default = ["verify" => __DIR__ . "/cacert.pem"];
$config = ["defaults" => $default];
$client = new Client($config);
$response = $client->get("https://www.facebook.com");