设置fabpot / goutte客户端的CURL参数 [英] Setting CURL Parameters for fabpot/goutte Client

查看:999
本文介绍了设置fabpot / goutte客户端的CURL参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用goutte(fabpot / goutte)工作。当我尝试连接到https网站时,它会抛出一个错误,因为该网站正在使用自签名证书。我试图找到设置curl参数的方式忽略ssl证书是自签名的事实。
按照 https://github.com/FriendsOfPHP/Goutte 中的说明操作,我尝试了以下操作代码:

  $ this-> client = new Client(); 
$ this-> client-> getClient() - > setDefaultOption('config / curl /'。CURLOPT_SSL_VERIFYPEER,false);
$ this-> client-> getClient() - > setDefaultOption('config / curl /'。CURLOPT_CERTINFO,false);不幸的是,当执行此代码时,会抛出以下错误:


$

 

Catchable致命错误:传递给GuzzleHttp \Client :: request()的参数3必须是数组类型,布尔值



无法弄清如何设置参数。呼叫如何预期?

解决方案

要设置curl选项,看起来像guzzle识别键curl配置设置,它接收curl相关配置值的数组。因此,您最初尝试实现的效果类似于以下



  $ client = new \Goutte\Client (); 

$ guzzleClient = new \GuzzleHttp\Client(array(
'curl'=> array(
CURLOPT_TIMEOUT => 60,
),
));
$ client-> setClient($ guzzleClient);
$ crawler = $ client-> request('GET',$ my_url);

不知道这是多么的支持,因为它没有在guzzle文档中的任何地方它以这种方式使它看起来像它依赖于CURL,我认为这不是guzzle的意图。因此一般超时配置条目)。


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.

解决方案

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).

这篇关于设置fabpot / goutte客户端的CURL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆