FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour CURL
Posts: 563
Joined: Sun Oct 09, 2005 07:23 PM
CURL
Posted: Mon Mar 25, 2019 02:25 PM
Cuando ejecuto el siguiente c贸digo no hace nada ni WINEXEC, ni MsgRun ni WaitRun.
Pero si lo aplico al NOTEPAD.EXE si funciona.
No lo entiendo

Code (fw): Select all Collapse
function curl_enviaFichero(cCertificado,cCertificadoKey,cFicheroAenviar,cFichRespAeat,cHttpAeat)
  local cText4Curl:='curl.exe --connect-timeout 60 -m 60 -S -L --cert ' + cCertificado + ' --key ' + cCertificadoKey +;
                    ' -d @' + cFicheroAenviar + ' -o "' + cFichRespAeat +'" ' +;
                    cHttpAeat
  
  //msginfo(cText4Curl)
  
   // NINGUNO DE LOS SIGUIENTES TRES COMANDOS FUNCIONA.
   WINEXEC(cText4Curl)
   MsgRun( 'Espere...',, { || WINEXEC(cText4Curl)} )
   WaitRun("C:\CLIWIN\AEAT\PruebaALB.BAT",.F.)

   // SIN EMBARGO. NOTEPAD SI LO ARRANCA BIEN Y MUESTRA EL FICHERO
   WaitRun("NOTEPAD.EXE "+cFicheroAenviar)
return


Por otro lado, cuando trato de usar las librer铆a de CURL me encuentro con que compila bien enlazando las libcur.lib de FW y la hbcurl.lib de harbour, adem谩s de colocar el #include "C:\hb32\contrib\hbcurl\hbcurl.ch" al principio del prg, pero al arrancar el exe generado me da aviso de error de sistema: La ejecuci贸n no puede continuar porque no se encontr贸 LIBCURL.DLL.
Y se sale del programa.
Estoy corriendo todo en Windows 10.
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: CURL
Posted: Mon Mar 25, 2019 03:17 PM
Ponle el path a CUrl.Exe.
Tambi茅n "recoge" la salida e inspeccionala.
Algo asi:

Code (fw): Select all Collapse
#Define PATH_CURL 聽 聽 聽 聽 AQUI_PONER_EL_PATH_DE_CURL
#Define FILE_CURL_SALIDA 聽"SalidaCurl.Txt"
聽local cText4Curl:=PATH_CURL+ '\'+ 'curl.exe --connect-timeout 60 -m 60 -S -L --cert ' + cCertificado + ' --key ' + cCertificadoKey +;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 ' -d @' + cFicheroAenviar + ' -o "' + cFichRespAeat +'" ' +;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 cHttpAeat+ " > "+ FILE_CURL_SALIDA
Posts: 563
Joined: Sun Oct 09, 2005 07:23 PM
Re: CURL
Posted: Mon Mar 25, 2019 03:36 PM
Con el c贸digo que sigue genera el archivo salida.txt peero est谩 vac铆o:
Code (fw): Select all Collapse
function CURL_enviaFichero(cCertificado,cCertificadoKey,cFicheroAenviar,cFichRespAeat,cHttpAeat)
 local cText4Curl:='C:\Windows\System32\curl.exe --connect-timeout 60 -m 60 -S -L --cert ' + cCertificado + ' --key ' + cCertificadoKey +;
                    ' -d @' + cFicheroAenviar + ' -o "' + cFichRespAeat +'" ' +;
                    cHttpAeat+ " > "+ "Salida.Txt"
  ShellExecute( 0, 'OPEN', "cmd" ,"/c "+cText4Curl, , 1 )
return


Con los comandos winxec, waitrun y msgrun no hace nada.

He comprobado si era un problema del firewall pero mi aplicaci贸n est谩 en la lista de excepciones.
Si esa instrucci贸n que trato de ejecutar desde dentro del prg la grabo en un .bat y la ejecuto desde fuera del programa entonces si la procesa.
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: CURL
Posted: Mon Mar 25, 2019 05:22 PM
Esto est谩 funcionando en producci贸n. Cambia tu segundo 60 por 300 y a m谩s a m谩s, adapta tus variables a este comando, a ver qu茅 tal.

Code (fw): Select all Collapse
cCommand:= "\Contabilidad\Sii\Curl.Exe -k --connect-timeout 60 -m 300 -s -S -L --header "Content-Type: text/xml;charset=UT8" --cert "\Contabilidad\Sii\Certificados\Certificado.Pem" --key "\Contabilidad\SiiCertificados\Certificado_key.Pem" --data @\Contabilidad\Error\Nif_Envio_4109979.xml <!-- m --><a class="postlink" href="https://www1.agenciatributaria.gob.es/wlpl/BURT-JDIT/ws/VNifV2SOAP">https://www1.agenciatributaria.gob.es/w ... VNifV2SOAP</a><!-- m --> --output \Contabilidad\Error\Nif_Respuesta_4109979.xml -v"

WaitRun(cCommand, 0)
Posts: 563
Joined: Sun Oct 09, 2005 07:23 PM
Re: CURL
Posted: Mon Mar 25, 2019 09:58 PM
Debe de ser una de esas sorpresas que el flamante Windows 10 tiene escondidas en lo m谩s intrincado de su naturaleza.

Resulta que si invocamos al curl.exe que trae el propio S.O. en la carpeta C:\Windows\system32, no lo encuentra cuando utilizamos los comandos mencionados en los post anteriores. Pero es m谩s, resulta que, a煤n estando all铆, no lo encuentra siquiera la instrucci贸n file("C:\Windows\System32\curl.exe").
Y si vas a verificar su existencia con el explorardor de windows, como digo, sin embargo all铆 est谩.

Para resolver el problema ha bastado con utilizar un curl otro cualquiera de los varios que aparecen instalados en el sistema, como el que viene con XAMPP (si lo teneis instalado) o el propio de harbour ubicado en: C:\hb32\comp\mingw\bin\curl.exe

Pero a qui茅n se le va a ocurrir que pasen estas cosas con windows, que no encuentre un archivo que si est谩.

Les dejo el c贸digo por si a alguien le puede ser de utilidad:
Code (fw): Select all Collapse
function CURL_enviaFichero(cCertificado,cCertificadoKey,cFicheroAenviar,cFichRespAeat,cHttpAeat)
 local cCurl    :="C:\hb32\comp\mingw\bin\curl.exe"
 local cOpciones:='--connect-timeout 60 -m 60 -S -L --cert ' + cCertificado + ' --key ' + cCertificadoKey +;
                    ' -d @' + cFicheroAenviar + ' -o "' + cFichRespAeat +'" ' +cHttpAeat+ " > "+ "Salida.Txt"
 
 local nErrorShellExecute:=32  // A partir del valor 32 inclusive es correcto y es el handler asignado al ejecutable
 
 if FILE(cCurl)
     nError = ShellExecute(oWnd,"Open",cCurl,cOpciones,,3)
     if nError < 32  //error
         msgstop(erroresShellExecute(nError),"ERROR AL EJECUTAR COMANDO DEL S.O.")
        else
         msginfo("COMANDO PROCESADO","INFORMACION")
     endif
    else
     msgstop("NO EXISTE EL PROGRAMA: "+cCurl,"ERROR DEL SISTEMA")
  endif

/*  Windows 10 NO lo encuentra a pesar de estar all铆 instalado. 25/03/2019.
  De modo que el siguiente c贸digo siempre devuelve el error n潞 2 de ShellExecute
  if FILE("C:\Windows\System32\curl.exe")
     nError = ShellExecute(oWnd,"Open","C:\Windows\System32\curl.exe",cOpciones,,3)
     if nError < 32  //error
         msgstop(erroresShellExecute(nError),"ERROR AL EJECUTAR COMANDO DEL S.O.")
        else
         msginfo("COMANDO PROCESADO","INFORMACION")
     endif
    else
     msgstop("NO EXISTE EL PROGRAMA: "+"C:\Windows\System32\curl.exe","ERROR DEL SISTEMA")
  endif
*/
return


/* Instrucciones de ShellExecute: 
   https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-shellexecutea#return-value
Devuelve:
El valor devuelto es el identificador de instancia de la aplicaci贸n que se abri贸 o se imprime, si la funci贸n se realiza correctamente. 
(Este controlador tambi茅n podr铆a ser el identificador de una aplicaci贸n de servidor DDE.) 
Una devoluci贸n de valor menor o igual a 32 especifica un error.

Errores:
La funci贸n ShellExecute() devuelve el valor 31 Si no hay ninguna asociaci贸n para el tipo de archivo especificado, 
o si no hay ninguna asociaci贸n para la acci贸n especificada en el tipo de archivo. 
Los dem谩s valores de error posibles son:*/                                     
function erroresShellExecute(nError)
 local nPos:=0
 local aErrores:={ {0, "System was out of memory, executable file was corrupt, or relocations were invalid."},;
                   {2, "File was not found."},;
                   {3, "Path was not found."},;
           {5, "Attempt was made to dynamically link to a task, or there was a sharing or network-protection error."},;
                   {6, "Library required separate data segments for each task."},;
                   {8, "There was insufficient memory to start the application."},;
                   {10,"Windows version was incorrect."},;
                   {11,"Executable file was invalid. Either it was not a Windows application, or there was an error in the .exe image."},;
                   {12,"Application was designed for a different operating system."},;
                   {13,"Application was designed for MS-DOS 4.0."},;
                   {14,"Type of executable file was unknown."},;
                   {15,"Attempt was made to load a real-mode application (developed for an earlier version of Windows)."},;
                   {16,"Attempt was made to load a second instance of an executable file containing multiple data segments that were not marked read-only."},;
                   {19,"Attempt was made to load a compressed executable file. The file must be decompressed before it can be loaded."},;
                   {20,"Dynamic-link library (DLL) file was invalid. One of the DLLs required to run this application was corrupt."},;
                   {21,"Application requires Microsoft Windows 32-bit extensions."},;
                   {31,"La extensi贸n del archivo no tiene asociaci贸n"} }
  nPos=ascan(aErrores,{|aVal| aVal[1]==nError})
return iif(nPos<>0,str(nError,3)+" - "+aErrores[nPos,2],"SIN ERRORES")
Posts: 17
Joined: Tue Oct 06, 2015 07:06 AM
Re: CURL
Posted: Tue Mar 26, 2019 07:35 AM
Por si quieres una alternativa a curl:

Code (fw): Select all Collapse
oWS := CreateObject("MSXML2.ServerXMLHTTP.6.0")
聽 聽if ValType(oWS)<>"O"
聽 聽 聽 MsgInfo("No tenemos el objeto...")
聽 聽 聽 return nil
聽 聽endif

聽 聽// Certificado que vamos a usar desde el almac茅n de certificados de Windows.
聽 聽oWS:SetOption(3, "Nombre del certificado")

聽 聽oWS :Open("POST", "https://www7.aeat.es/wlpl/SSII-FACT/ws/fe/SiiFactFEV1SOAP", .f.)

聽 聽// Establecer el timeout de la operaci贸n:
聽 聽// resolveTimeout, connectTimeout, sendTimeout, receiveTimeout
聽 聽// Los valores son en milisegundos:
聽 聽oWS :setTimeouts(15000,15000, 600000, 600000)

聽 聽// El m茅todo al que vamos a llamar.
聽 聽oWS:SetRequestHeader("SOAPAction", "SuministroLRFacturasEmitidas")

聽 聽cXML := MemoRead(archivoxml)

聽 聽// Enviamos la informaci贸n del XML.
聽 聽oWS:send(cXML)

聽 聽MsgInfo("Respuesta: "+oWS:responsexml:xml)
聽 聽// Analizar la respuesta...


Un saludo.

Continue the discussion