PHP PhantomJS忽略SSL证书

时间:2015-10-25 20:52:21

标签: php ssl phantomjs

我想解析一个HTTPS网页,但是当我这样做时它是空白的。 所以我认为它与SSL证书有关。 我怎么能忽略这个?

我正在使用php-phantomjs

1 个答案:

答案 0 :(得分:7)

如问题PhantomJS failing to open HTTPS site中所示,您可能需要添加以下命令行选项来修复SSL / TLS问题:

phantomjs --ssl-protocol=any --ignore-ssl-errors=true --web-security=false script.js

php-phantomjs中的用法是little different,但你可以使用:

$client = Client::getInstance();
$client->getEngine()->addOption('--ssl-protocol=any');
$client->getEngine()->addOption('--ignore-ssl-errors=true');
$client->getEngine()->addOption('--web-security=false');

或者像这样加载一个config.json文件:

$client->getEngine()->addOption('--config=/path/to/config.json');

config.json:

{
    "sslProtocol": "any",
    "ignoreSslErrors": true,
    "webSecurityEnabled": false
}

在旧版本的php-phantomjs中,必须使用$client->addOption(...)而不是$client->getEngine()->addOption(...)