elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


  Mostrar Temas
Páginas: [1]
1  Programación / PHP / cURL error 77 al conectar una https con certificado en: 21 Junio 2017, 21:35 pm
Saludos amigos(as) del foro: tengo una gran inquietud en función que deseo obtener unos datos de una web que requiere autentificacion y la misma tiene un certificado digital el codigo que llevo hasta ahora es el siguiente
Código
  1.                                $username = "xxxxxxxxx";
  2.                                $password = "xxxxxxxxx";
  3.                                $ci_nC = $_POST['consulta'];
  4.                                $sección="1";
  5.                                $ubicacion_menu="ubicacion_menu.php";
  6.                                $verifiCed="xxxxxx";
  7.                                $url = "https://direcciondeacceso.com/index.php";
  8.                                $url2 = "https://direcciondeacceso.com/consulta.php/";
  9.                                $header = "Content-type: application/x-www-form-urlencoded";
  10.  
  11.                                /* Primera petición */
  12.                                // Login
  13.                                $raw_post =  "&". http_build_query(array("LOGIN" => $username));
  14.                                $raw_post .= "&". http_build_query(array("CLAVE" => $password));
  15.                                $ch = curl_init($url);
  16.                                curl_setopt($ch, CURLOPT_POST,1);
  17.                                curl_setopt($ch, CURLOPT_TIMEOUT, 15 );
  18.                                curl_setopt($ch, CURLOPT_POSTFIELDS , utf8_encode( $raw_post ) );
  19.                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  20.                                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
  21.                                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
  22.                                curl_setopt($ch, CURLOPT_CAINFO, getcwd().'../certificado.crt' );
  23.                                curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  24.                                curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
  25.                                curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
  26.                                $buffer  = curl_exec( $ch );
  27.                                $errorcURL = curl_errno( $ch );
  28.                                curl_close( $ch );  
  29.  
  30.                                if($errorcURL){
  31.                                    echo "ERROR: ".$errorcURL."</BR>";
  32.                                }                              
  33.                                // Segunda peticion de datos
  34.                                $raw_post2 =  "&". http_build_query(array("consulta" => $ci_nC));
  35.                                $raw_post2 .= "&". http_build_query(array("ubicacion_menu" => $ubicacion_menu));
  36.                                $ch = curl_init($url2);
  37.                                curl_setopt($ch, CURLOPT_POSTFIELDS , utf8_encode( $raw_post2 ) );
  38.                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  39.                                curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  40.                                curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
  41.                                curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
  42.                                $buffer  = curl_exec( $ch );
  43.                                $errorcURL2 = curl_errno( $ch );
  44.                                curl_close( $ch );
  45.                                if($errorcURL){
  46.                                    echo "ERROR: ".$errorcURL2."</BR>";
  47.                                }  
  48.  
  49.  
  50.                                if ( preg_match("|<td class='cnt-color2'>(.*?)</td>|is",$buffer,$cap) )
  51.                                {
  52.                                        echo "respuesta 1";
  53.                                }else{
  54.                                    echo "respuesta 2";
  55.                                }
  56.  

Ahora bien el problema en si, es que no logro que pase de la primera consulta, aun dando los datos de logeo correctos no pasa por la parte del certificado según presumo por el tipo de error del curl_errno = "77". Un dato adicional es que al acceder a la web en cuestión a través del navegador "chrome" en este caso me da un error NET::ERR_CERT_AUTHORITY_INVALID que normalmente le doy a opciones avanzadas y acceso sin mayor dificultad, aunque no se si esto afecta el logueo a traves del cURL
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines