php curl -k 或 --insecure, -X
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15232977/
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
php curl -k or --insecure, -X
提问by Doo Dah
With PHP & curl, I need to connect via a proxy to a SSL secured site, and, ignore certificate warnings. My curl command line looks like this:
使用 PHP 和 curl,我需要通过代理连接到 SSL 安全站点,并忽略证书警告。我的 curl 命令行如下所示:
curl -k -u username:password -X GET https://someURL
Looking through curl.php, I see what I think are the correct options to set. With them, I end up with something like this:
查看 curl.php,我看到了我认为要设置的正确选项。有了他们,我最终得到了这样的结果:
$ch = curl_init("https://someURL");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Ignore cert errors?
curl_setopt($ch, CURLOPT_PROXY, true); // Proxy true?
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
$result = curl_exec($ch);
But, $result always returns false. My password has a special character in it, "!". Perhaps I need to escape it? Other than that, any other ideas?
但是,$result 总是返回 false。我的密码中有一个特殊字符“!”。也许我需要逃避它?除此之外,还有其他想法吗?
回答by hek2mgl
To completely disable ssl certificate checking curl knows the option CURLOPT_SSL_VERIFYPEER. If it is set to falsecertifcate checking will be disabled at all. As the default value is true, you'll have to add:
要完全禁用 ssl 证书检查 curl 知道该选项CURLOPT_SSL_VERIFYPEER。如果它设置为false证书检查将被禁用。由于默认值为true,您必须添加:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
From the PHP documentation:
从PHP 文档:
CURLOPT_SSL_VERIFYPEERFALSE to stop cURL from verifying the peer's certificate. Alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option. TRUE by default as of cURL 7.10. Default bundle installed as of cURL 7.10.
CURLOPT_SSL_VERIFYPEERFALSE 以阻止 cURL 验证对等方的证书。可以使用 CURLOPT_CAINFO 选项指定要验证的替代证书,或者可以使用 CURLOPT_CAPATH 选项指定证书目录。自 cURL 7.10 起默认为 TRUE。从 cURL 7.10 开始安装的默认包。
Note that if certificate checking is disabled you can omit the CURLOPT_SSL_VERIFYHOSTsetting. So the following line can be removed:
请注意,如果禁用了证书检查,则可以省略该CURLOPT_SSL_VERIFYHOST设置。因此可以删除以下行:
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
You also asked if the following setting is ok:
您还询问以下设置是否可以:
curl_setopt($ch, CURLOPT_PROXY, true);
From the PHP documentation:
从PHP 文档:
The HTTP proxy to tunnel requests through.
用于通过隧道传输请求的 HTTP 代理。
Means that it accepts a proxy address like '192.168.0.1:3128' if you are using a proxy. trueis not meaningful in this case
意味着如果您使用代理,它接受像“192.168.0.1:3128”这样的代理地址。true在这种情况下没有意义

