Ir al contenido


Foto

Curl - RETURN NOTHING


  • Por favor identifícate para responder
49 respuestas en este tema

#1 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 15 marzo 2012 - 05:04

Hola

Estoy creando un cliente que consume un webservice con curl, pero, estoy teniendo un problemas cuando envío archivos, después de la línea donde espera el resultado:



delphi
  1. curlResult := curl_easy_perform(Curl);



curlResult dice "CURL RETURN NOTHING", ésto lo hace cuando los archivos son muy grandes, cuando envío archivos pequeños si me regresa el CONTENT.

¿ Hay alguna forma de indicarle que espere por datos ? un simple sleep no me funciona :(

Saludos y gracias.

  • 0

#2 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 15 marzo 2012 - 05:29

Este es el error que me regresa

Server returned nothing (no headers, no data)


Pero en realidad si me regresa datos, con soapUI recibo esto

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Header>
      <wsse:Security S:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsu:Created>2012-03-15T23:28:50Z</wsu:Created>
            <wsu:Expires>2012-03-15T23:29:50Z</wsu:Expires>
        </wsu:Timestamp>
      </wsse:Security>
  </S:Header>
  <S:Body>
      <ns24:registroDigitalizarDocumentoServiceResponse xmlns="http://www.ventanillaunica.gob.mx/common/ws/oxml/respuesta" xmlns:ns10="http://www.ventanillaunica.gob.mx/common/ws/oxml/establecimiento" xmlns:ns11="http://www.ventanillaunica.gob.mx/gubernamentales2/cofepris/ws/oxml/solicitud" xmlns:ns12="http://www.ventanillaunica.gob.mx/common/ws/oxml/declaracion" xmlns:ns13="http://www.ventanillaunica.gob.mx/common/ws/oxml/pago" xmlns:ns14="http://www.ventanillaunica.gob.mx/gubernamentales2/cofepris/ws/oxml/tramite/" xmlns:ns15="http://www.ventanillaunica.gob.mx/gubernamentales2/cofepris/ws/oxml/respuesta" xmlns:ns16="http://www.ventanillaunica.gob.mx/gubernamentales2/cofepris/ws/oxml/dictamen" xmlns:ns17="http://www.ventanillaunica.gob.mx/gubernamentales2/cofepris/ws/oxml/observacion" xmlns:ns18="http://www.ventanillaunica.gob.mx/gubernamentales2/cofepris/ws/oxml/requisito" xmlns:ns19="http://www.ventanillaunica.gob.mx/common/ws/oxml/usuario" xmlns:ns2="http://www.ventanillaunica.gob.mx/aga/digitalizar/ws/oxml/DigitalizarDocumento" xmlns:ns20="http://www.ventanillaunica.gob.mx/common/ws/oxml/mercancia" xmlns:ns21="http://www.ventanillaunica.gob.mx/gubernamentales2/cofepris/ws/oxml/mercancia" xmlns:ns22="http://www.ventanillaunica.gob.mx/common/ws/oxml/uso" xmlns:ns23="http://www.ventanillaunica.gob.mx/gubernamentales2/cofepris/ws/oxml/opinion" xmlns:ns24="http://www.ventanillaunica.gob.mx/aga/digitalizar/ws/oxml/" xmlns:ns3="http://www.ventanillaunica.gob.mx/gubernamentales2/cofepris/ws/oxml" xmlns:ns4="http://www.ventanillaunica.gob.mx/common/ws/oxml/documento" xmlns:ns5="http://www.ventanillaunica.gob.mx/common/ws/oxml/respuestatra" xmlns:ns6="http://www.ventanillaunica.gob.mx/common/ws/oxml/tramite" xmlns:ns7="http://www.ventanillaunica.gob.mx/common/ws/oxml/solicitud" xmlns:ns8="http://www.ventanillaunica.gob.mx/common/ws/oxml/persona" xmlns:ns9="http://www.ventanillaunica.gob.mx/common/ws/oxml/direccion">
        <ns2:respuestaBase>
            <tieneError>false</tieneError>
        </ns2:respuestaBase>
        <ns2:acuse>
            <ns2:numeroOperacion>222</ns2:numeroOperacion>
            <ns2:horaRecepcion>2012-03-15T17:28:50.091-06:00</ns2:horaRecepcion>
            <ns2:mensaje>Su petición se encuentra procesando</ns2:mensaje>
        </ns2:acuse>
      </ns24:registroDigitalizarDocumentoServiceResponse>
  </S:Body>
</S:Envelope>


:(

Saludos
  • 0

#3 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 16 marzo 2012 - 02:55

Ya intenté otra modificación



delphi
  1.     if curl_easy_setopt(Curl, CURLOPT_CONNECTTIMEOUT, 30) <> CURLE_OK then exit;
  2.     if curl_easy_setopt(Curl, CURLOPT_TIMEOUT, 180) <> CURLE_OK then exit;



ninguna de las dos me funcionó :(

Saludos

  • 0

#4 seoane

seoane

    Advanced Member

  • Administrador
  • 1.259 mensajes
  • LocationEspaña

Escrito 16 marzo 2012 - 02:58

¿Puedes poner algo de código?
  • 0

#5 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 16 marzo 2012 - 03:05

¿Puedes poner algo de código?




delphi
  1. function TDigital.EnviarPost(Url, Post: AnsiString; out Reply: TStrings): Boolean;
  2.  
  3.       //***********************************************************************************
  4.       function ReadFromStream(Buffer: PAnsiChar; Size, Count: Integer;
  5.         Stream: TStream): Integer; cdecl;
  6.       begin
  7.         Result:= Stream.Read(Buffer^,Size*Count) div Size;
  8.       end;
  9.  
  10.       function SaveToStream(Buffer: PAnsiChar; Size, Count: Integer;
  11.         Stream: TStream): Integer; cdecl;
  12.       begin
  13.         Result:= Stream.Write(Buffer^,Size*Count) div Size;
  14.       end;
  15.  
  16.       function MemoryStreamToString(M:TMemoryStream): AnsiString;
  17.       begin
  18.         SetString(Result, PChar(M.Memory), M.Size);
  19.       end;
  20.       //***********************************************************************************
  21.  
  22.       procedure ErrorCurl(const mensaje: string);
  23.       begin
  24.         raise Exception.Create(mensaje);
  25.         exit;
  26.       end;
  27.  
  28. begin
  29.   Result:= false;
  30.   Curl:= curl_easy_init;
  31.   if Curl <> nil then
  32.   try
  33.     if curl_easy_setopt(Curl, CURLOPT_VERBOSE, TRUE) <> CURLE_OK then
  34.       ErrorCurl('No se pudo asignar CURLOPT_VERBOSE.');
  35.     if curl_easy_setopt(Curl, CURLOPT_USE_SSL, CURLUSESSL_ALL) <> CURLE_OK then
  36.       ErrorCurl('No se pudo asignar CURLOPT_USE_SSL.');
  37.     if curl_easy_setopt(Curl, CURLOPT_SSL_VERIFYPEER, FALSE) <> CURLE_OK then
  38.       ErrorCurl('No se pudo asignar CURLOPT_SSL_VERIFYPEER.');
  39.     if curl_easy_setopt(Curl, CURLOPT_URL, PAnsiChar(URL)) <> CURLE_OK then
  40.       ErrorCurl('No se pudo asignar CURLOPT_URL.');
  41.     if curl_easy_setopt(Curl, CURLOPT_POST, 1) <> CURLE_OK then
  42.       ErrorCurl('No se pudo asignar CURLOPT_POST.');
  43.     if curl_easy_setopt(Curl, CURLOPT_READFUNCTION, @ReadFromStream) <> CURLE_OK then
  44.       ErrorCurl('No se pudo asignar CURLOPT_READFUNCTION.');
  45.     if curl_easy_setopt(Curl, CURLOPT_WRITEFUNCTION, @SaveToStream) <> CURLE_OK then
  46.       ErrorCurl('No se pudo asignar CURLOPT_WRITEFUNCTION.');
  47.     if curl_easy_setopt(Curl, CURLOPT_WRITEFUNCTION, @SaveToStream) <> CURLE_OK then
  48.       ErrorCurl('No se pudo asignar CURLOPT_WRITEFUNCTION.');
  49.     if curl_easy_setopt(Curl, CURLOPT_CONNECTTIMEOUT, 30) <> CURLE_OK then
  50.       ErrorCurl('No se pudo asignar CURLOPT_CONNECTTIMEOUT.');
  51.     if curl_easy_setopt(Curl, CURLOPT_TIMEOUT, 180) <> CURLE_OK then
  52.       ErrorCurl('No se pudo asignar CURLOPT_TIMEOUT.');
  53.  
  54. //    if FproxyCurl.proxyIP <> '' then
  55. //    begin
  56. //      if curl_easy_setopt(Curl, CURLOPT_HTTPPROXYTUNNEL, 1) <> CURLE_OK then
  57. //        ErrorCurl('No se pudo asignar CURLOPT_HTTPPROXYTUNNEL.');
  58. //      if curl_easy_setopt(Curl, CURLOPT_PROXY, FproxyCurl.proxyIP + ':' + FproxyCurl.proxyPort ) <> CURLE_OK then
  59. //        ErrorCurl('No se pudo asignar CURLOPT_PROXY.');
  60. //
  61. //      if FproxyCurl.proxyUsr <> '' then
  62. //      begin
  63. //        if curl_easy_setopt(Curl, CURLOPT_PROXYUSERPWD, FproxyCurl.proxyUsr + ':' + FproxyCurl.proxyPwd ) <> CURLE_OK then
  64. //          ErrorCurl('No se pudo asignar CURLOPT_PROXYUSERPWD.');
  65. //      end;
  66. //    end;
  67.  
  68.     Stream    := TMemoryStream.Create;
  69.     StreamOut := TMemoryStream.Create;
  70.  
  71.     try
  72.       with TStringList.Create do
  73.       try
  74.         Add(Post);
  75.         SaveToStream(Stream);
  76.       finally
  77.         Free;
  78.       end;
  79.       Stream.Position:= 0;
  80.       if curl_easy_setopt(Curl, CURLOPT_INFILE, Stream) <> CURLE_OK then
  81.         ErrorCurl('No se pudo asignar CURLOPT_INFILE.');
  82.       if curl_easy_setopt(Curl, CURLOPT_POSTFIELDSIZE, Stream.Size) <> CURLE_OK then
  83.         ErrorCurl('No se pudo asignar CURLOPT_POSTFIELDSIZE.');
  84.       Header := nil;
  85.       Header := curl_slist_append(Header,PAnsiChar('Expect:'));
  86.       Header := curl_slist_append(Header,PAnsiChar('Content-Type: text/xml;charset=UTF-8'));
  87.       Header := curl_slist_append(Header,PAnsiChar('SOAPAction: "urn:'+FsoapAction+'"'));
  88.       Header := curl_slist_append(Header,PAnsiChar('Accept: text/xml'));
  89.       Header := curl_slist_append(Header,PAnsiChar('Accept-Encoding: gzip,deflate,identity'));
  90.       Header := curl_slist_append(Header,PAnsiChar('User-Agent: Jakarta Commons-HttpClient/3.1'));
  91.  
  92.       try
  93.         if curl_easy_setopt(Curl, CURLOPT_FILE, StreamOut) <> CURLE_OK then
  94.           ErrorCurl('No se pudo asignar CURLOPT_FILE.');
  95.         if curl_easy_setopt(Curl, CURLOPT_HTTPHEADER, Header) <> CURLE_OK then
  96.           ErrorCurl('No se pudo asignar CURLOPT_HTTPHEADER.');
  97.  
  98.         curlResult := curl_easy_perform(Curl);
  99.  
  100.  
  101.         if curlResult = CURLE_OK then
  102.         begin
  103.           Reply.Text := MemoryStreamToString(StreamOut);
  104.           curlError := '';
  105.           result := true;
  106.         end
  107.         else begin
  108.               curlError := curl_easy_strerror(curlResult);
  109.               Reply.Text := curlError;
  110.               result := false;
  111.         end;
  112.  
  113.       finally
  114.         curl_slist_free_all(Header);
  115.       end;
  116.     finally
  117.       Stream.Free;
  118.       StreamOut.Free;
  119.     end;
  120.   finally
  121.     curl_easy_cleanup(Curl);
  122.   end;
  123. end;



ésto es lo que hago amigo.

Le he quitado lo del proxy porque pensé que por ahí podía estar el problema.

Y solo tengo problema cuando el archivo enviado es muy grande

Saludos


  • 0

#6 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 16 marzo 2012 - 03:08

Aclaro que el proxy no es necesario, no hay proxy.

Saludos
  • 0

#7 seoane

seoane

    Advanced Member

  • Administrador
  • 1.259 mensajes
  • LocationEspaña

Escrito 16 marzo 2012 - 03:19

No veo nada raro. ¿El parámetro Post que contiene?
  • 0

#8 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 16 marzo 2012 - 03:25

Un archivo XML que incluye un pdf en base64, éste mide mas de 6MB, sí lo transmite bien porque me llega un correo con la validación de lo que envié, lo que no me llega es la respuesta de la operación, si mando un archivo de pocos K's si me llega la respuesta.

Yo necesito esa respuesta porque me envía el número de operación que utilizaré para consultar la respuesta para que sea un proceso automatizado y no tener que consultar hasta que llega el correo.

Saludos
  • 0

#9 seoane

seoane

    Advanced Member

  • Administrador
  • 1.259 mensajes
  • LocationEspaña

Escrito 16 marzo 2012 - 05:22

Al parecer puede haber un problema al subir archivos grandes, a veces es necesario reenviar parte del fichero al servidor. En ese caso curl intentara leer otra vez ese trozo pero se encontrara con el problema de que no puede volver atrás en la lectura del stream y no terminara de enviar los datos al servidor, por lo que este tampoco responde y ahí tenemos el error del que hablas.

Podemos probar a solucionarlo añadiendo la funcion "seek" permitiendo a curl volver atrás dentro del stream


delphi
  1. // No esta completa pero para probar nos servira
  2. function SeekStream(Stream: TStream; Offset: int64; Origin: Integer): Integer; cdecl;
  3. begin
  4.   Stream.Seek(Offset, soFromBeginning);
  5.   Result:= 0;
  6. end;



Y recuerda anadirla con setopt:


delphi
  1. if curl_easy_setopt(Curl, CURLOPT_SEEKFUNCTION, @SeekStream) <> CURLE_OK then
  2.   ErrorCurl('No se pudo asignar CURLOPT_SEEKFUNCTION.');
  3. if curl_easy_setopt(Curl, CURLOPT_SEEKDATA, Stream) <> CURLE_OK then
  4.   ErrorCurl('No se pudo asignar CURLOPT_SEEKDATA.');



Ahora mismo me voy para cama  |-) pero pruebala y me cuentas.

En cualquier caso el problema lo mas seguro que venga por ahí, es decir, la comunicación se esta reiniciando y curl de forma silenciosa intenta el reenvió, pero como no puede terminarlo devuelve ese error. Habría que ver porque es produce ese error, y si hay manera de configurar curl para que no intente el reenvió y devuelva la primera respuesta.

Pero eso sera mañana  |-)
  • 0

#10 Fenareth

Fenareth

    Advanced Member

  • Administrador
  • 3.486 mensajes
  • LocationMexico City

Escrito 16 marzo 2012 - 05:55

Pero si no son ni las 6 de la tarde...  :| :| :| :| :| :| :| :|

*-) *-) *-) *-) *-) *-)  :D :D :D :D :D :D :D

Buenas noches del otro lado del charco...  |-) |-) |-) |-) |-) |-)

Saludox ! :)


  • 0

#11 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 16 marzo 2012 - 06:20

Muchas gracias amigo Seoane, ya lo pruebo y te comento los resultados.

Saludos

  • 0

#12 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 17 marzo 2012 - 10:25

Hola

Pues no resultó :(


Iniciando POST 10:23:51
Server returned nothing (no headers, no data)
Termina POST 10:28:52



Aunque si me llega el correo de que se recibió correctamente el archivo. :(

Saludos

  • 0

#13 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 17 marzo 2012 - 10:41

Recorté el archivo y lo envié y si me regresó información

Iniciando POST 10:38:43 907




<?xml version='1.0' encoding='UTF-8'?>
  <S:Envelope>
      <S:Header>
            <wsse:Security>
                    <wsu:Timestamp >
                            <wsu:Created>2012-03-17T16:40:33Z</wsu:Created>
                            <wsu:Expires>2012-03-17T16:41:33Z</wsu:Expires>
                    </wsu:Timestamp>
            </wsse:Security>
      </S:Header>
      <S:Body>
              <ns2:respuestaBase>
                        <tieneError>true</tieneError>
                        <error>
                              <mensaje>La cadena original es inválida</mensaje>
                        </error>
              </ns2:respuestaBase>
      </S:Body>
  </S:Envelope>


Termina POST 10:38:46 832

Saludos

  • 0

#14 seoane

seoane

    Advanced Member

  • Administrador
  • 1.259 mensajes
  • LocationEspaña

Escrito 17 marzo 2012 - 03:46

Pues no se me ocurre que puede ser ¿probaste a aumentarle el timeout a un valor MUY grande?  *-)

El problemas para "debugar" este código es que la comunicación va cifrada, de forma que no podemos echarle un vistazo a lo que se envía y se recibe. Tendríamos que ver que es exactamente lo que esta pasando, si como dices el archivo esta llegando bien el problema debe de ser que curl no esta interpretando bien las respuestas del servidor, o que por algún motivo esta intentando hacer reenvios.

Pero como ya te dije sin poder echar un vistazo a la "conversación" entre curl y el servidor es muy difícil encontrar el problema.  Creo que había algunas funciones de curl para hacer debug, si las pudiéramos utilizar seria mas fácil encontrar el problema.

Habrá que buscar en la documentación ...
  • 0

#15 seoane

seoane

    Advanced Member

  • Administrador
  • 1.259 mensajes
  • LocationEspaña

Escrito 17 marzo 2012 - 09:11

Vamos a probar con el debug a ver que sale. Pon esta función en tu código:


delphi
  1. function DebugFunc(Curl: TCURL; InfoType: Integer; Text: PAnsiChar; Size: Integer; Stream: TStream): Integer; cdecl;
  2. var
  3.   Str: String;
  4. begin
  5.   Str:= #13#10 + FormatDateTime('[dd/mm/yy hh:hh:ss:zzz]',Now);
  6.   Str:= Str + Format(' %8.8x:%8.8x',[Integer(Curl),InfoType]) + #13#10;
  7.   Stream.Write(PAnsiChar(Str)^,Length(Str));
  8.   Stream.Write(Text^,Size);
  9.   Result:= 0;
  10. end;



Y luego añádela con curl_easy_setopt:


delphi
  1.       if curl_easy_setopt(Curl, CURLOPT_DEBUGFUNCTION, @DebugFunc) <> CURLE_OK then
  2.         Exit;
  3.       if curl_easy_setopt(Curl, CURLOPT_DEBUGDATA, DebugStream) <> CURLE_OK then
  4.         Exit;



En este ejemplo "DebugStream" es un TMemoryStream. Puedes crearlo antes de hacer el envio y al terminar guardarlo en un archivo antes de destruirlo.

Así tendremos toda la información acerca de lo que pasa dentro de libcurl, así como una copia de toda la comunicación.

Algo así:


delphi
  1. [18/03/12 04:04:03:878] 0180F720:00000000
  2. About to connect() to smtp.gmail.com port 465 (#0)
  3.  
  4. [18/03/12 04:04:03:879] 0180F720:00000000
  5.   Trying 173.194.67.108...
  6. [18/03/12 04:04:03:882] 0180F720:00000000
  7. connected
  8.  
  9. [18/03/12 04:04:03:882] 0180F720:00000000
  10. Connected to smtp.gmail.com (173.194.67.108) port 465 (#0)
  11.  
  12. [18/03/12 04:04:05:242] 0180F720:00000000
  13. successfully set certificate verify locations:
  14.  
  15. [18/03/12 04:04:05:242] 0180F720:00000000
  16.   CAfile: cacert.pem
  17.   CApath: none
  18.  
  19. [18/03/12 04:04:05:243] 0180F720:00000000
  20. SSLv3, TLS handshake, Client hello (1):



Pruebalo, y sube aquí el fichero que generes con los mensajes de debug para que le podamos echar un vistazo

Saludos
  • 0

#16 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 17 marzo 2012 - 09:20

Ahora mismo lo hago amigo, voy llegando a casa después de un largo día de andar en la calle :)

Saludos
  • 0

#17 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 17 marzo 2012 - 09:34

Hola amigo, no te pongo todo lo que capturó porque son mas de 6 megas, pero te pongo lo que regresa después de que termina de enviar el xml.


[17/03/12 21:21:48:759] 0175A818:00000000
Empty reply from server

[17/03/12 21:21:48:759] 0175A818:00000000
Connection #0 to host www2.ventanillaunica.gob.mx left intact

[17/03/12 21:21:48:759] 0175A818:00000000
Server returned nothing (no headers, no data)


Saludos

Edito:

Ésto puede ser relevante, antes de enviar el XML, no se.


[17/03/12 21:21:51:426] 0175A818:00000000
SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.


  • 0

#18 seoane

seoane

    Advanced Member

  • Administrador
  • 1.259 mensajes
  • LocationEspaña

Escrito 18 marzo 2012 - 03:55

No creo que sea ese el problema. Si puedes subelo todo en un zip, o mandamelo por correo.
  • 0

#19 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 18 marzo 2012 - 08:08

Hola amigo, ya te envíe por mensaje un link para que lo descargues.

Saludos
  • 0

#20 seoane

seoane

    Advanced Member

  • Administrador
  • 1.259 mensajes
  • LocationEspaña

Escrito 18 marzo 2012 - 09:29

Hola amigo, ya te envíe por mensaje un link para que lo descargues.


Pues ahora estoy todavía mas confuso :(

Segun el log todo sale bien, no hay ni errores, ni reenvios, ni nada ... La única explicación que se me ocurre es el timeout, aunque ya vi que probaste a ponerle 3 minutos ¿probaste a poner 1 hora?

Siento no poder ser de mas ayuda. :(
  • 0




IP.Board spam blocked by CleanTalk.