当Guzzlehttp用于从某些网站获取数据时,为什么会出现错误?

时间:2017-02-28 19:29:01

标签: php http guzzlehttp

我编写了以下代码来从网页中获取数据。

require_once 'vendor/autoload.php';

    $client = new \GuzzleHttp\Client(['base_uri' => $uri]);
    $response = $client->request('GET');

    if($response->getStatusCode() == 200) {
        $body = $response->getBody();
        echo $body;
    }

然而,并非总能正常工作。当$uri = http://httpbin.org时,代码完美无缺。但是当$uri = https://www.yandex.ru时,它会产生一些致命的错误而失败。谁能解释为什么会这样?怎么解决这个问题?
编辑:这是我收到的错误 Fatal error: 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:\Xampp\htdocs\Guzzle\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:187 Stack trace: #0 C:\Xampp\htdocs\Guzzle\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(150): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array) #1 C:\Xampp\htdocs\Guzzle\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(103): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #2 C:\Xampp\htdocs\Guzzle\vendor\guzzlehttp\guzzle\src\Handler\CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #3 C:\Xampp\htdocs\Guzzle\vendor\guzzlehttp\guzzle in C:\Xampp\htdocs\Guzzle\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 187

0 个答案:

没有答案