问题
I am working on a web crowler using goutte (fabpot/goutte). When I try to connect to an https site, it throws an error because the site is using a self signed certificate. I am trying to find the way to set the curl parameters to ignore the fact that the ssl certificate is self signed. Following the instructions in https://github.com/FriendsOfPHP/Goutte I tried the following code:
$this->client = new Client();
$this->client->getClient()->setDefaultOption('config/curl/'.CURLOPT_SSL_VERIFYPEER, false);
$this->client->getClient()->setDefaultOption('config/curl/'.CURLOPT_CERTINFO, false);
Unfortunately when this code is executed the following error is thrown:
Catchable fatal error: Argument 3 passed to GuzzleHttp\Client::request() must be of the type array, boolean given
Can't figure out how to set up the parameters. How is the call expected? Any help will be appreciated.
回答1:
To set curl options by the way, it looks like guzzle recognizes the key "curl" as a config setting, which takes in an array of curl-related config values. So the equivalent of what you were initially trying to achieve would look like the following
$client = new \Goutte\Client();
$guzzleClient = new \GuzzleHttp\Client(array(
'curl' => array(
CURLOPT_TIMEOUT => 60,
),
));
$client->setClient($guzzleClient);
$crawler = $client->request('GET', $my_url);
Not sure how well this is supported since it isn't indicated anywhere in the guzzle docs (and doing it this way makes it look like its dependent on CURL, which I think is not the intention of guzzle. Hence the general timeout config entry).
回答2:
What I ended up doing is the following:
$this->client->setClient(new GuzzleClient(['verify' => false]));
The 'verify' => false when initiating the GuzzleClient makes it not verify the certificates.
来源:https://stackoverflow.com/questions/37324500/setting-curl-parameters-for-fabpot-goutte-client