2

我正在使用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();

}

4

2 回答 2

1

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

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

$config =array('verify' => 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();
于 2017-06-13T16:31:26.430 回答
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
    ))); 
于 2013-09-06T21:38:10.970 回答