Ver Mensaje Individual
  #4 (permalink)  
Antiguo 28/05/2010, 11:34
Avatar de neodani
neodani
 
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 1 mes
Puntos: 20
Respuesta: Se puede enviar datos con CURL a paginas ASP?

Buenas,

Estoy teniendo problemas para enviar por datos por POST a un script.

El primer inconveniente que veo es que no puedo enviarle directamente al script los datos...

Procedimiento usuario:
Entrar en la web https://www.bookingh10hotels.com
Pulsar sobre el botón "Reservar un hotel", nos llevara a una página la cual no se puede acceder directamente sin haber pulsado previamente ese botón.
Una vez en esa pagina pulsar sobre el boton azul oscuro que dice "CLUB H10 y Promociones", esto mostrará una capa que esta oculta con un formulario.
Este formulario está publicado más abajo "comentado en el código".
Es desde ahí donde se debe enviar por POST (entiendo la única variable), CodPromocion.

Para ello he construido lo siguiente:

Código PHP:
Ver original
  1. <?php
  2.    
  3. $cookietmp='.';
  4. $target_url = "https://www.bookingh10hotels.com";
  5.  
  6.  
  7. $ch = curl_init();
  8. curl_setopt($ch, CURLOPT_URL, $target_url);
  9. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookietmp);
  10. curl_setopt($ch, CURLOPT_FAILONERROR, true);
  11. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  12. curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
  14. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  15. curl_setopt($ch, CURLOPT_TIMEOUT, 180);
  16. $html = curl_exec($ch);
  17.  
  18. /* Una vez llegados aqui, interesa enviar el formulario siguiente por POST */
  19.  
  20. $target_url2="https://www.bookingh10hotels.com/reservasweb/cargar_grupo_codPromo_post.asp";
  21.  
  22. $fields = array(
  23.     'CodPromocion'=>"1234",
  24.     );
  25.  
  26. foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
  27. rtrim($fields_string,'&');
  28.  
  29. curl_setopt($ch, CURLOPT_URL, $target_url2);
  30. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookietmp);
  31. curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
  32. curl_setopt($ch, CURLOPT_FAILONERROR, true);
  33. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  34. curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  35. curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
  36. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  37. curl_setopt($ch, CURLOPT_TIMEOUT, 180);
  38. $html2 = curl_exec($ch);
  39.  
  40. echo "<pre>";
  41. echo $html2;
  42. echo "</pre>";
  43.  
  44. /*
  45.  
  46. <form action="cargar_grupo_codPromo_post.asp" method="POST">
  47.     <tr>
  48.         <td><br><u>Código Promocional</u></td>
  49.     </tr>
  50.     <tr>
  51.         <td colspan=3>Si dispones de un código promocional o de colectivo, introdúcelo aquí. Los códigos promocionales no son acumulables a otras ofertas ni promociones, <br><br></td>
  52.     </tr>
  53.     <tr>
  54.         <td></td>
  55.         <td align="center"><input type="text" name="CodPromocion" maxlength=20 value=""></td>
  56.         <td><input type="submit" class="BotonEnviarPagPresup" value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enviar&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"></td>
  57.     </tr>
  58. </form>
  59.  
  60. */
  61. ?>

El procedimiento FALLA, cuando intento hacer la otra petición
Warning: curl_exec(): 2 is not a valid cURL handle resource in C:\AppServ\www\00-laboratorio_test\secciones\CURL\curl_hoteles.php on line 39

¿Qué estoy haciendo mal?

¿Se puede hacer de una manera más directa?

Si os fijáis intento hacer una segunda conexión aprovechando que estoy en una pagina... pero no se si esto es posible :S

Muchas gracias de antemano!