Problem with Domdocument Openssl

Asked

Viewed 168 times

0

I’m trying to get information from a website using DOMDocument but you’re making a mistake.

DOMDocument::loadHTMLFile(): SSL operation failed with code 1. 
OpenSSL Error messages: error:14090086:SSL 
routines:ssl3_get_server_certificate:certificate verify failed    



 $html = new DOMDocument();
 $html->loadHTMLFile("https://sistemasweb.sefaz.ba.gov.br/sistemas/DTE/Contribuinte/SSL/ASLibrary/Login");
 $dado = $html->getElementsByTagName('__EVENTVALIDATION');
 echo $dado;

1 answer

0

The problem is the address certificate https://sistemasweb.sefaz.ba.gov.br/sistemas/DTE/Contribuinte/SSL/ASLibrary/Login, it is invalid, but it can also occur, even if they fix the site, your PHP not having the certificates configured, for future chance try this /a/137009/3635, who would stay:

$context = stream_context_create(array(
    "ssl"=>array(
        "cafile" => "/path/cacert.pem",
        "verify_peer"=> true,
        "verify_peer_name"=> true
    )
));

libxml_set_streams_context($context);

Or configure php.ini properly:

openssl.cafile=/path/cacert.pem

And restart Apache or Nginx. However it is as said, the above solutions will not work, are for when the site you are trying to access is with the certificate fixed, for now you can disable the SSL check so:

$context = stream_context_create(array(
    "ssl"=>array(
        'verify_peer' => false,
        'verify_peer_name' => false
    )
));

libxml_set_streams_context($context);

$html = new DOMDocument();
$html->loadHTMLFile("https://sistemasweb.sefaz.ba.gov.br/sistemas/DTE/Contribuinte/SSL/ASLibrary/Login");
$dado = $html->getElementsByTagName('__EVENTVALIDATION');

echo $dado;

If eventually the libxml_set_streams_context not working can try changing the approach to:

$context = stream_context_create(array(
    "ssl"=>array(
        'verify_peer' => false,
        'verify_peer_name' => false
    )
));

$conteudosite = file_get_contents("https://sistemasweb.sefaz.ba.gov.br/sistemas/DTE/Contribuinte/SSL/ASLibrary/Login", false, $context);

$html = new DOMDocument();
$html->loadHTML($conteudosite);

$dado = $html->getElementsByTagName('__EVENTVALIDATION');

echo $dado;
  • 1

    The certificate is valid, but the certification authority that issued it is not recognised (the key corresponds to the certificate, but the verification on the list of recognized authorities failed). They are quite different things. The answer deserves a small adjustment in this sense.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.