php 如何在 Guzzle 5 中忽略无效的 SSL 证书错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28066409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to ignore invalid SSL certificate errors in Guzzle 5
提问by Gnuffo1
This should be an easy thing to do. I can find plenty of references to how to do it in Guzzle 3, but they don't work in Guzzle 5.
这应该是一件容易的事情。我可以在 Guzzle 3 中找到大量有关如何执行此操作的参考资料,但它们在 Guzzle 5 中不起作用。
What I am doing so far:
到目前为止我在做什么:
$this->client = new GuzzleClient(['defaults' => [
'verify' => 'false'
]]);
When I send a request though I get this error:
当我发送请求时,虽然收到此错误:
RequestException in RequestException.php line 51:
SSL CA bundle not found: false
I cannot find any useful reference to this error on google. If I could get access to the curl options then I could try something like the solution suggested here (which is for Guzzle 3, hence why it doesn't work): http://inchoo.net/dev-talk/symfony2-guzzle-ssl-self-signed-certificate/, the relevant section of which is:
我在谷歌上找不到对此错误的任何有用参考。如果我可以访问 curl 选项,那么我可以尝试类似于此处建议的解决方案(适用于 Guzzle 3,因此它不起作用):http://inchoo.net/dev-talk/symfony2-guzzle -ssl-self-signed-certificate/,其相关部分是:
$req->getCurlOptions()->set(CURLOPT_SSL_VERIFYHOST, false);
$req->getCurlOptions()->set(CURLOPT_SSL_VERIFYPEER, false);
回答by pjcdawkins
You should use
你应该使用
$this->client = new GuzzleClient(['defaults' => [
'verify' => false
]]);
i.e. a Boolean false, not the string 'false'
即布尔值 false,而不是字符串 'false'
The documentation is here: http://docs.guzzlephp.org/en/latest/request-options.html#verify
文档在这里:http: //docs.guzzlephp.org/en/latest/request-options.html#verify
回答by SND
Try with updated version that works:
尝试使用有效的更新版本:
$this->client = new GuzzleClient(['base_uri' => 'https://api.example.com/', 'verify' => false ]);
or a more simple version:
或更简单的版本:
$this->client = new GuzzleClient(['verify' => false ]);
Tested with version 6.2-dev.
使用版本 6.2-dev 进行测试。
回答by PriNcee
The actual version is the correct one:
实际版本是正确的:
$this->client = new GuzzleClient(['verify' => false ]);
At 2018, this does not work:
在 2018 年,这不起作用:
$this->client = new GuzzleClient(['defaults' => [
'verify' => false
]]);