Mink - Goutte驱动程序cURL SSL错误

时间:2013-05-21 03:45:00

标签: mink goutte guzzle

我正在使用Mink 1.4,使用Goutte驱动程序。

我试图在页面中设置一些表单字段值,然后单击提交该表单的按钮。

但后来我收到了这个错误

Fatal error: Uncaught exception 'Guzzle\Http\Exception\CurlException' with message ' in phar://C:/Documents and Settings/User/My Documents/Dropbox/kar_rental/inc/mink.phar/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php on line 579

Guzzle\Http\Exception\CurlException: [curl] 60: SSL certificate problem, verify that the CA cert is OK...

我认为由于我将CURLOPT_SSL_VERIFYPEER设置为false,因此不应检查SSL。

这是我的代码:

foreach ($this->_sites_data as $site_name => $site_data)
{
    // Instantiate Mink's Goutte Driver
    $clientOptions = array(
        'curl.options' => array(
            'CURLOPT_SSL_VERIFYPEER' => false,
            'CURLOPT_CERTINFO' => false,
            'CURLOPT_TIMEOUT' => 120
        ),
        'ssl.certificate_authority' => 'system'
    );

$client = new \Behat\Mink\Driver\Goutte\Client();
$client->setClient(new \Guzzle\Http\Client($site_data['form_data']['form_url'], $clientOptions));

$driver = new \Behat\Mink\Driver\GoutteDriver($client);

// Initialize Mink
$session = new \Behat\Mink\Session($driver);

// Start session
$session->start();

foreach ($site_data['form_data']['post_fields'] as $days => $post_fields)
{
    // Open form page
    $session->visit($site_data['form_data']['form_url']);
    $page = $session->getPage();

    foreach ($post_fields as $post_field_name => $post_field_value)
    {
        $el = $page->find('css', '#' . $post_field_name);
        $el->setValue($post_field_value);
    }

    $el = $page->find('css', $site_data['form_data']['submit_element_css']);
    $el->click();
}

$session->reset();

}

2 个答案:

答案 0 :(得分:1)

我找到了适用于Behat / Mink ^ 1.6和Behat / mink-goutte-driver ^ 1.2的配置。

事情是将验证错误作为配置数组传递给Guzzle客户端:

$ config = array('验证' => false);

在这里,您是我的通用用例:

    $client = new \Behat\Mink\Driver\Goutte\Client();
    $driver = new \Behat\Mink\Driver\GoutteDriver($client);

    $client->setClient(new \GuzzleHttp\Client(array(
        'verify' => false,
    )));

    //$driver = new \Behat\Mink\Driver\GoutteDriver($client);
    $session = new \Behat\Mink\Session($driver);

    $session->start();

    $session->visit(YOUR_URL_COMES_HERE);
    echo $session->getPage()->getOuterHtml();

    $session->stop();

答案 1 :(得分:0)

在Goutte中禁用SSL检查

在你的behat.yml文件中

goutte: 
     guzzle_parameters:
           curl.options:
              CURLOPT_SSL_VERIFYPEER: false
              CURLOPT_CERTINFO: false
              CURLOPT_TIMEOUT: 120
           ssl.certificate_authority: false

如果失败,请尝试:

<?php
use Guzzle\Http\Client as GuzzleClient;
$client = new \Behat\Mink\Driver\Goutte\Client();
$gouttedriver = new \Behat\Mink\Driver\GoutteDriver(
    $client
);
$client->setClient(new GuzzleClient('', array(
     'curl.CURLOPT_SSL_VERIFYPEER' => false,
     'curl.CURLOPT_CERTINFO'       => false
    )));