Ver Mensaje Individual
  #5 (permalink)  
Antiguo 28/02/2012, 22:12
dvex_92
 
Fecha de Ingreso: septiembre-2011
Ubicación: Peru - Lima
Mensajes: 16
Antigüedad: 12 años, 7 meses
Puntos: 0
Exclamación Respuesta: ¿Como puedo enviar datos a un WebService usando cURL?

Uuhhmmm.. Como te dije en un principio.. si mando en forma de cadena los datos usando http_build_query() o en array.
Directamente me da igual el error 500 Internal server error.

ya que.. si mando por arreglo asociativo los datos. El header se cambia a "Content-Type: multipart/form-data". Si lo mando como un string, el header cambia a: "Content-Type:w-xxx-urlencoded" (oh algo asi creo q es). Pienso que daria lo mismo. Corrigeme si me equivoco porfavor.

Código PHP:
Ver original
  1. $ch = curl_init();
  2.         // Aqui siempre me redirige a la url de logeo.
  3.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  4.         curl_setopt($ch, CURLOPT_HEADER, TRUE);
  5.         curl_setopt($ch, CURLOPT_URL, $url_target);
  6.         curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
  7.         curl_setopt($ch, CURLOPT_TIMEOUT, 50);
  8.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  9.         $result = curl_exec($ch); //The page redirect
  10.         $getinfo = curl_getinfo($ch, CURLINFO_HTTP_CODE); //I get http_code=302
  11.        
  12.         if(preg_match('#Location: (.*)#', $result, $r))
  13.                 $url_redirect = trim($r[1]); //Here i obtain the URL of login of my webservice
  14.  
  15.         /* Here is for login.. Is it correct?
  16.             Aqui si estoy con muchas dudas.
  17.             Porque me pide un logeo comun y corriente.
  18.             Y nose si lo estaré haciendo bien.
  19.         */
  20.         curl_setopt($ch, CURLOPT_URL, $url_redirect);
  21.         curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  22.         curl_setopt($ch, CURLOPT_USERPWD, $userpwd);
  23.         curl_setopt($ch, CURLOPT_HEADER, TRUE);
  24.         curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
  25.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  26.         curl_setopt($ch, CURLOPT_TIMEOUT, 50);
  27.         $page = curl_exec($ch); // Return me a string: Evaluating...
  28.         $getinfo = curl_getinfo($ch, CURLINFO_HTTP_CODE); //I get http_code=200
  29.        
  30.         /* Here is for send the data to the webservice: $url_target... It is correct?*/
  31.         curl_setopt($ch, CURLOPT_POST, TRUE);
  32.         curl_setopt($ch, CURLOPT_POSTFIELDS, $attendee);
  33.         curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
  34.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  35.         curl_setopt($ch, CURLOPT_TIMEOUT, 50);
  36.         $result = curl_exec($ch); // Return me a string: Evaluating...
  37.         $getinfo = curl_getinfo($ch, CURLINFO_HTTP_CODE);// I get http_code=200
  38.    
  39.     curl_close($ch);

Sin embargo, aunque me salga todo el codigo 200. Al ver mi webservice no pasa nada. No recibe ningun dato, no lo muestra.

Y si.. Intente hacerlo con el http_build_query() pero igual me da el mismo resultado. Nose que estaré haciendo mal.

Pido que me corrigas, quizas halla algo que no vea bien. De antemano Muchas gracias por su apoyo :D

Última edición por dvex_92; 28/02/2012 a las 22:22