0
我想使用Guzzle從網頁獲取數據。我寫了下面的代碼:使用Guzzle獲取遠程數據
<?php
require_once 'vendor/autoload.php';
$client = new \GuzzleHttp\Client(['base_uri' => 'https://yandex.ru']);
$response = $client->request('GET');
$body = $response->getBody();
echo $body;
但我收到致命錯誤,當我在我的本地主機上運行此代碼。
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
問題是,當我刪除我的代碼的最後三行時,它運作良好,所以問題與請求。任何人都可以提出解決方案
更改默認值驗證爲false,看看它是否工作。 **新的GuzzleClient(['defaults'=> [ 'verify'=> false ]]); ** – Dimi
我剛試過,但沒有幫助 –
您是否嘗試指定'verify'=> false選項在請求級別? http://docs.guzzlephp.org/en/latest/request-options.html#verify – Gabriel