我想使用Guzzle和Silex来发送请求到https页面。
对于http url,我得到了一个响应:
app->get('/',function() use ($app, $client){
$response = $client->get("http://www.google.fr");
var_dump($response);
}); 我的回答是:
object(GuzzleHttp\Message\Response)[102]
private 'reasonPhrase' => string 'OK' (length=2)
private 'statusCode' => int 200
private 'effectiveUrl' => string 'http://www.google.fr' (length=20)
private 'headers' (GuzzleHttp\Message\AbstractMessage) =>
array (size=13)
'date' =>
array (size=1)
0 => string 'Wed, 18 Feb 2015 10:57:37 GMT' (length=29)
'expires' => 但使用https:
$app->get('/',function() use ($app, $client){
$url = "https://api.zoapp.com/v1/stc/cans/directory/pub/Employees";
$response = $client->get("https://www.facebook.com/");
var_dump($response);
});我有很多错误:
RequestException in RequestException.php line 51:和
RingException in CurlFactory.php line 126:详情:pastbin link
发布于 2015-04-12 18:29:10
在链接到详细信息后,异常消息会显示:
cURL错误60:请参阅http://curl.haxx.se/libcurl/c/libcurl-errors.html
查找我找到的http://curl.haxx.se/libcurl/c/libcurl-errors.html
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时显式设置证书更容易。这意味着:
中此证书的本地路径
示例(假设您将名为cacert.pem的证书与脚本位于同一目录中):
$default = ["verify" => __DIR__ . "/cacert.pem"];
$config = ["defaults" => $default];
$client = new Client($config);
$response = $client->get("https://www.facebook.com");发布于 2015-02-18 19:37:06
我找到了一个解决方案,但不知道它为什么有效:
$client->setDefaultOption('verify', false);
$response = $client->get("https://www.facebook.com");https://stackoverflow.com/questions/28582091
复制相似问题