简体   繁体   English

使用GuzzleHttp时出现cURL错误60

[英]cURL error 60 while using the GuzzleHttp

I would like to get rid of this error. 我想摆脱这个错误。 I read a similar question where one answer suggested that I can disable the verification using: 我读了一个类似的问题 ,其中一个答案建议我可以使用以下方式禁用验证:

$client->setDefaultOption('verify', false);

My exact error is: 我的确切错误是:

Uncaught exception 'GuzzleHttp\\Exception\\RequestException' with message 'cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html )' in C:\\path\\guzzle\\src\\Handler\\CurlFactory.php:187 Stack trace: #0 C:\\path\\guzzle\\src\\Handler\\CurlFactory.php(150): GuzzleHttp\\Handler\\CurlFactory::createRejection(Object(GuzzleHttp\\Handler\\EasyHandle), Array) #1 未捕获的异常“ GuzzleHttp \\ Exception \\ RequestException”,消息为“ cURL错误60:SSL证书问题:无法获取本地发行者证书(请参阅http://curl.haxx.se/libcurl/c/libcurl-errors.html )” C:\\ path \\ guzzle \\ src \\ Handler \\ CurlFactory.php:187堆栈跟踪:#0 C:\\ path \\ guzzle \\ src \\ Handler \\ CurlFactory.php(150):GuzzleHttp \\ Handler \\ CurlFactory :: createRejection(Object( GuzzleHttp \\ Handler \\ EasyHandle),数组)#1

C:\\path\\guzzle\\src\\Handler\\CurlFactory.php(103): GuzzleHttp\\Handler\\CurlFactory::finishError(Object(GuzzleHttp\\Handler\\CurlHandler), Object(GuzzleHttp\\Handler\\EasyHandle), Object(GuzzleHttp\\Handler\\CurlFactory)) #2 C:\\ path \\ guzzle \\ src \\ Handler \\ CurlFactory.php(103):GuzzleHttp \\ Handler \\ CurlFactory :: finishError(Object(GuzzleHttp \\ Handler \\ CurlHandler),Object(GuzzleHttp \\ Handler \\ EasyHandle),Object(GuzzleHttp \\ Handler) \\ CurlFactory))#2

C:\\path\\guzzle\\src\\Handler\\CurlHandler.php(43): GuzzleHttp\\Handler\\CurlFactory::finish(Object(GuzzleHttp\\Handler\\CurlHandler), Object(GuzzleHttp\\Handler\\EasyHandle), Object(GuzzleHttp\\Hand in C:\\path\\guzzle\\src\\Handler\\CurlFactory.php on line 187 C:\\ path \\ guzzle \\ src \\ Handler \\ CurlHandler.php(43):GuzzleHttp \\ Handler \\ CurlFactory :: finish(Object(GuzzleHttp \\ Handler \\ CurlHandler),Object(GuzzleHttp \\ Handler \\ EasyHandle),Object(GuzzleHttp \\ Hand)在第187行的C:\\ path \\ guzzle \\ src \\ Handler \\ CurlFactory.php中

I read the code of all these lines and there is no variable like $client there but I found this function inside CurlFactory.php . 我读了所有这些行的代码,那里没有像$client这样的变量,但是我在CurlFactory.php找到了这个函数。 Please note the file CurlFactory.php was not created by me. 请注意,文件CurlFactory.php不是我创建的。

public function release(EasyHandle $easy)
{
    $resource = $easy->handle;
    unset($easy->handle);

    if (count($this->handles) >= $this->maxHandles) {
        curl_close($resource);
    } else {
        // Remove all callback functions as they can hold onto references
        // and are not cleaned up by curl_reset. Using curl_setopt_array
        // does not work for some reason, so removing each one
        // individually.
        curl_setopt($resource, CURLOPT_HEADERFUNCTION, null);
        curl_setopt($resource, CURLOPT_READFUNCTION, null);
        curl_setopt($resource, CURLOPT_WRITEFUNCTION, null);
        curl_setopt($resource, CURLOPT_PROGRESSFUNCTION, null);
        curl_reset($resource);
        $this->handles[] = $resource;
    }
}

Can I set the option to disable verification here? 我可以在此处设置禁用验证的选项吗?

I know it is not a good idea to disable verification but the code is for personal use and to test something. 我知道禁用验证不是一个好主意,但是代码仅供个人使用和测试。 It is no problem if I disable the verification. 如果我禁用验证没问题。 Here is the code in my actual PHP file. 这是我实际的PHP文件中的代码。

require('vendor/autoload.php');
use JonathanTorres\MediumSdk\Medium;

$medium = new Medium('my-key');

$user = $medium->getAuthenticatedUser();
echo 'Authenticated user name is: ' . $user->name;

As you can see, I am not using cURL in my code anywhere. 如您所见,我没有在代码中的任何地方使用cURL。 The options need to be set inside the library somewhere. 这些选项需要在库中某个地方设置。 Is it possible to disable the verification in my own file instead of changing the source code of library? 是否可以在我自己的文件中禁用验证,而不用更改库的源代码?

You're probably looking for the option CURLOPT_SSL_VERIFYHOST . 您可能正在寻找选项CURLOPT_SSL_VERIFYHOST If not specified, this setting defaults to option 2, which means the connection will fail if the certificate name does not match the name of the server connected to. 如果未指定,则此设置默认为选项2,这意味着如果证书名称与连接的服务器名称不匹配,则连接将失败。 Setting this to 0 means that the host name will be ignored, and the certificate will be accepted regardless of name mismatch. 将此设置为0意味着将忽略主机名,并且将接受证书,而不考虑名称不匹配。 Usually this is enough to address issues with self-signed certificates. 通常,这足以解决自签名证书的问题。

Option 1 is a legacy option which used to be used for debugging but is deprecated and should not be used. 选项1是旧选项,以前用于调试,但已弃用,不应使用。

This could also be due to curl not being able to find the root certificate bundle. 这也可能是由于curl无法找到根证书捆绑包。 You can download the bundle from the curl site and save it to a location on your server, then add a reference to it in your php.ini like so: curl.cainfo = FOLDER_PATH\\cacert.pem 您可以从curl网站下载捆绑软件并将其保存到服务器上的某个位置,然后像这样在php.ini中添加对它的引用:curl.cainfo = FOLDER_PATH \\ cacert.pem

It could also be related to the version of Guzzle, I found references to this being a problem with Guzzle versions later than 4 . 它也可能与Guzzle的版本有关,我发现这是Guzzle迟于4版本的问题。 Not sure if that's practical for you to try. 不确定是否可以尝试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM