0

I have written the following code to fetch data from webpages.

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;
    }

However, not always it works correctly. When $uri = http://httpbin.org, the code perfectly works. But when $uri = https://www.yandex.ru, for example, it gives some fatal error and fails. Could anyone explain why this happens? How can this be solved?
EDIT: This is the error I get 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 Answers0