Page 1 of 1
Capturar el motivo del error petición web (curl)
Posted: Thu Oct 20, 2022 9:33 pm
by leandro
Hola buenas tardes,
En algunas ocasiones y dependiendo de la maquina desde donde se lance la petición, la aplicación no logra enviar la solicitud ohttp:Send, nosotros colocamos un mensaje personalizado que indica que no se pudo enviar; existe alguna forma de capturar el motivo especifico por el cual no se pudo enviar la petición.
Cabe aclarar que hay conexión a internet y la url a la cual estamos consultando tambien existe, como digo funciona correctamente en otros computares que están conectados a la misma LAN.
Code: Select all | Expand
cBas64 := hb_base64encode(::user+":"+::pass,len(::user+":"+::pass))
ohttp := CreateObject( "MSXML2.XMLHTTP" )
ohttp:Open( "POST" , ::urlenvio ,.F.)
oHttp:SetRequestHeader("cache-control", "no-cache")
ohttp:SetRequestHeader("content-type", "application/json" )
ohttp:SetRequestHeader("authorization", "Basic "+cBas64 )
TRY
ohttp:Send( ::cdnaJson )
CATCH
//NOS GUSTARIA PODER CAPTURAR EL ERROR Y SABER EL MOTIVO POR EL QUE NO SE PUDO ENVIAR
msginfo("No Se Pudo Enviar Documento JSON - Error URL","error url")
END
Re: Capturar el motivo del error petición web (curl)
Posted: Fri Oct 21, 2022 5:53 am
by cnavarro
leandro wrote:Hola buenas tardes,
En algunas ocasiones y dependiendo de la maquina desde donde se lance la petición, la aplicación no logra enviar la solicitud ohttp:Send, nosotros colocamos un mensaje personalizado que indica que no se pudo enviar; existe alguna forma de capturar el motivo especifico por el cual no se pudo enviar la petición.
Cabe aclarar que hay conexión a internet y la url a la cual estamos consultando tambien existe, como digo funciona correctamente en otros computares que están conectados a la misma LAN.
Code: Select all | Expand
cBas64 := hb_base64encode(::user+":"+::pass,len(::user+":"+::pass))
ohttp := CreateObject( "MSXML2.XMLHTTP" )
ohttp:Open( "POST" , ::urlenvio ,.F.)
oHttp:SetRequestHeader("cache-control", "no-cache")
ohttp:SetRequestHeader("content-type", "application/json" )
ohttp:SetRequestHeader("authorization", "Basic "+cBas64 )
TRY
ohttp:Send( ::cdnaJson )
CATCH
//NOS GUSTARIA PODER CAPTURAR EL ERROR Y SABER EL MOTIVO POR EL QUE NO SE PUDO ENVIAR
msginfo("No Se Pudo Enviar Documento JSON - Error URL","error url")
END
Leandro
Code: Select all | Expand
TRY
ohttp:Send( ::cdnaJson )
cRet := ohttp:ResponseText
CATCH
//NOS GUSTARIA PODER CAPTURAR EL ERROR Y SABER EL MOTIVO POR EL QUE NO SE PUDO ENVIAR
msginfo("No Se Pudo Enviar Documento JSON - Error URL","error url")
? cRet
END
También has de valorar usar la libreria CURL
Re: Capturar el motivo del error petición web (curl)
Posted: Fri Oct 21, 2022 1:11 pm
by csincuir
Leandro, aparte de lo que te envió Cristobal, tal vez te sirva esto:
Code: Select all | Expand
TRY
ohttp:Send( ::cdnaJson )
cRet := ohttp:ResponseText
CATCH oError
MsgInfo( "Error" + CRLF + "Error: " + cValToChar( oError:GenCode) + CRLF + ;
"SubC: " + cValToChar( oError:GenCode) + CRLF + "OSCode: " + cValToChar( oError:GenCode) + CRLF + ;
"SubSystem: " + cValToChar( oError:SubSystem ) + CRLF + "Envio de CURL: " + oError:Description )
//NOS GUSTARIA PODER CAPTURAR EL ERROR Y SABER EL MOTIVO POR EL QUE NO SE PUDO ENVIAR
msginfo("No Se Pudo Enviar Documento JSON - Error URL","error url")
? cRet
END
Saludos
Carlos.
Re: Capturar el motivo del error petición web (curl)
Posted: Fri Oct 21, 2022 2:32 pm
by leandro
Muchas gracias por las respuestas, creo que la de Carlos es la que mas se ajusta a nuestra necesidad.
El motivo del error:
Code: Select all | Expand
Error: 1001 SubC: 1001
OSCode: 1001
SubSystem: MSXML2.XMLHTTP
Envio de CURL: DISP_E_MEMBERNOTFOUND
Alguien sabe como lo podemos solucionar?
Amigo Cristóbal, en donde encuentro ejemplos sobre la librería curl?
Re: Capturar el motivo del error petición web (curl)
Posted: Fri Oct 21, 2022 2:55 pm
by cnavarro
leandro wrote:Muchas gracias por las respuestas, creo que la de Carlos es la que mas se ajusta a nuestra necesidad.
El motivo del error:
Code: Select all | Expand
Error: 1001 SubC: 1001
OSCode: 1001
SubSystem: MSXML2.XMLHTTP
Envio de CURL: DISP_E_MEMBERNOTFOUND
Alguien sabe como lo podemos solucionar?
Amigo Cristóbal, en donde encuentro ejemplos sobre la librería curl?
Entonces es que no te he entendido: si lo que pretendes es capturar un error de programación o ejecución, estoy de acuerdo. Si lo que necesitas es capturar si la respuesta del API o servicio web que estás atacando te devuelve un código de error te recomiendo que uses lo que te he puesto y analices el contenido de la respuesta que te da el servidor ( no hay una forma genérica de hacerlo, ya que cada server devolverá según esté programado el API o servicio )
En cuanto a la libreria CURL hay bastantes ejemplos en el foro, pero miro a ver si te puedo construir ese mismo ejemplo.
Re: Capturar el motivo del error petición web (curl)
Posted: Sat Oct 22, 2022 2:11 am
by leandro
Amigo buenas noches como estas?
Revisando en el foro, puede encontrar un ejemplo que publicaste, para compilar con xharbour, incluyendo la librería hbcur.lib. Pero agregando la función que colocaste me salen los siguientes errores:
http://forums.fivetechsupport.com/viewtopic.php?f=3&t=40437&p=241434&hilit=curl+xharbour&sid=83943fd443094141a77f5e0834bb4ac0&sid=d699d9e1c47f549e8b8a5829430cb47c#p241692Tampoco encuentro el #include "hbcurl.ch"
Code: Select all | Expand
Turbo Incremental Link 6.80 Copyright (c) 1997-2017 Embarcadero Technologies, Inc.
Error: Unresolved external '_curl_global_init_mem' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_global_cleanup' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_formfree' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_easy_cleanup' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_easy_reset' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_easy_duphandle' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_easy_init' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_easy_pause' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_easy_perform' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_easy_send' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_easy_recv' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_formadd' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_slist_append' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_easy_setopt' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_easy_getinfo' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_slist_free_all' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_easy_escape' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_easy_unescape' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_version' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_version_info' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_easy_strerror' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_getdate' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_escape' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_unescape' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unresolved external '_curl_free' referenced from C:\XHAR1906\LIB\HBCURL.LIB|hbcurl
Error: Unable to perform link
Link Error
Te agradecería si tienes entre tus cosas un ejemplo funciona para xharbour

de antemano gracias.
Re: Capturar el motivo del error petición web (curl)
Posted: Sat Oct 22, 2022 6:03 am
by cnavarro
Añade las librerias libcurl.lib y hbcurl.lib
Re: Capturar el motivo del error petición web (curl)
Posted: Sat Oct 22, 2022 2:48 pm
by leandro
Amigo de nuevo gracias por responder
Agregue las librerías como mencionaste, permitió compilar, agregue hbcurl.ch, tambien me pidió la libcurl.dll, la cual copie en la carpeta al lado del ejecutable.
Pero al lanzar la función ejemplo sale el siguiente error:

Re: Capturar el motivo del error petición web (curl)
Posted: Wed Nov 02, 2022 2:06 am
by leandro
Buenas noches para todos
Error: 1001 SubC: 1001
OSCode: 1001
SubSystem: MSXML2.XMLHTTP
Envio de CURL: DISP_E_MEMBERNOTFOUND
hemos logrado detectar que el error mencionado con anterioridad, solo sale cuando direccionamos al servidor nuevo, en el anterior funciona de manera correcta. De casualidad alguien sabe a que se pueda deber? es necesario instalar algún complemento en el nuevo servidor, algo de seguridad?
Cabe recordar que solo sucede en algunos computadores, sobre todo en los que tienen windows7.
y que la prueba se hizo en el mismo computador y lo único que cambiamos fue la dirección web.
Cuando lo direccionamos al servidor
https://hymplus.com/servicios/autorizados funciona
correctamente
pero al direccionarlo al servidor
https://hymlyma.com/servicios/autorizados es en donde sale el
error
Re: Capturar el motivo del error petición web (curl)
Posted: Sat Nov 05, 2022 9:06 pm
by leandro
Buenas tardes para todos
Bueno les cuento que buscando solucionar este problema que tenemos, logramos compilar la aplicación con harbour, como nos recomendó Cristobal, estamos intentando usar la libreria curl, el problema ahora es que no logramos que el servidor nos entregue una respuesta. Necesitamos ayuda para traducir el código que veníamos usando por el de la libreria curl.
Código anterior
Code: Select all | Expand
cBas64 := hb_base64encode(::user+":"+::pass,len(::user+":"+::pass))
ohttp := CreateObject( "MSXML2.XMLHTTP" )
ohttp:Open( "POST" , ::urlenvio ,.F.)
oHttp:SetRequestHeader("cache-control", "no-cache")
ohttp:SetRequestHeader("content-type", "application/json" )
ohttp:SetRequestHeader("authorization", "Basic "+cBas64 )
TRY
ohttp:Send( ::cdnaJson )
response := ohttp:responseText
CATCH oError
cError := "Error: " + cValToChar( oError:GenCode) + ;
" SubC: " + cValToChar( oError:GenCode) + " OSCode: " + cValToChar( oError:GenCode) + CRLF + ;
"SubSystem: " + cValToChar( oError:SubSystem ) + CRLF + "Envio de CURL: " + oError:Description
exito := {.f.,cError}
return exito
END
Código con curl, que encontramos en el foro
Code: Select all | Expand
cBas64 := hb_base64encode(::user+":"+::pass,len(::user+":"+::pass))
curl_global_init()
hCurl := curl_easy_init()
if !empty( hCurl )
curl_easy_setopt( hCurl, HB_CURLOPT_URL, ::urlenvio )
AAdd( aHeaders, "authorization: Basic "+cBas64 )
AAdd( aHeaders, "content-type : application/json" )
AAdd( aHeaders, "cache-control : no-cache" )
curl_easy_setopt( hCurl, HB_CURLOPT_HTTPHEADER, aHeaders )
curl_easy_setopt( hCurl, HB_CURLOPT_CONNECTTIMEOUT , 100 )
curl_easy_setopt( hCurl, HB_CURLOPT_POST, 1)
curl_easy_setopt( hCurl, HB_CURLOPT_CUSTOMREQUEST, "POST")
curl_easy_setopt( hCurl, HB_CURLOPT_POSTFIELDS, ::cdnaJson )
curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYHOST, .F. )
curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )
cError := curl_easy_perform( hCurl )
if !Empty( cError )
MsgInfo( curl_easy_strerror( cError ), "Error" )
endif
cTexto := curl_easy_dl_buff_get( hCurl )
fw_memoedit( cTexto ) //Creo que aqui viene la respuesta
curl_easy_reset( hCurl )
endif
curl_global_cleanup()
Este es el error que se captura en el fw_memoedit()
Code: Select all | Expand
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>
Luego de esto la aplicación se cierra sin que muestre ningún error y tampoco genera el error en el archivo error.log
De antemano gracias por la ayuda
Re: Capturar el motivo del error petición web (curl)
Posted: Sat Nov 05, 2022 10:18 pm
by cnavarro
Mira a ver si algo de esto te ayuda
Code: Select all | Expand
curl_easy_setopt( oCurl, HB_CURLOPT_SSL_VERIFYPEER, 0 )
curl_easy_setopt( oCurl, HB_CURLOPT_ENCODING, "UTF-8" )
Do Case
Case cType == "POST"
curl_easy_setopt( oCurl, HB_CURLOPT_DL_BUFF_SETUP )
curl_easy_setopt( oCurl, HB_CURLOPT_POST, 1 )
// //curl_easy_setopt( oCurl, HB_CURLOPT_CUSTOMREQUEST, "POST" )
if !Empty( cParams )
curl_easy_setopt( oCurl, HB_CURLOPT_POSTFIELDS, cParams )
endif
EndCase
Re: Capturar el motivo del error petición web (curl)
Posted: Sat Nov 05, 2022 11:43 pm
by leandro
No nada, sigue igual
Code: Select all | Expand
curl_global_init()
hCurl := curl_easy_init()
if !empty( hCurl )
curl_easy_setopt( hCurl, HB_CURLOPT_URL, ::urlenvio )
AAdd( aHeaders, "authorization: Basic "+cBas64 )
AAdd( aHeaders, "content-type : application/json" )
AAdd( aHeaders, "cache-control : no-cache" )
curl_easy_setopt( hCurl, HB_CURLOPT_HTTPHEADER, aHeaders )
curl_easy_setopt( hCurl, HB_CURLOPT_CONNECTTIMEOUT , 100 )
curl_easy_setopt( hCurl, HB_CURLOPT_POST, 1)
//curl_easy_setopt( hCurl, HB_CURLOPT_CUSTOMREQUEST, "POST")
curl_easy_setopt( hCurl, HB_CURLOPT_POSTFIELDS, ::cdnaJson )
curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYHOST, .F. )
curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )
curl_easy_setopt( hCurl, HB_CURLOPT_ENCODING, "UTF-8" )
cError := curl_easy_perform( hCurl )
if !Empty( cError )
MsgInfo( curl_easy_strerror( cError ), "Error" )
endif
cTexto := curl_easy_dl_buff_get( hCurl )
fw_memoedit( cTexto ) //Creo que aqui viene la respuesta
curl_easy_reset( hCurl )
endif
curl_global_cleanup()
Re: Capturar el motivo del error petición web (curl)
Posted: Sun Nov 06, 2022 2:46 am
by cnavarro
Añade al principio
Code: Select all | Expand
curl_easy_setopt( oCurl, HB_CURLOPT_DEFAULT_PROTOCOL, "https" )
Re: Capturar el motivo del error petición web (curl)
Posted: Sun Nov 06, 2022 11:52 am
by leandro
Amigo gracias por la ayuda
Ahora sale este error:
Code: Select all | Expand
Application
===========
Path and name: C:\DLYMA\hymlyma.exe (32 bits)
Size: 8,435,200 bytes
Compiler version: Harbour 3.2.0dev (r2008190002)
FiveWin version: FWH 21.06
C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
Windows version: 6.2, Build 9200
Time from start: 0 hours 0 mins 35 secs
Error occurred at: 06/11/2022, 06:51:16
Error description: Error BASE/1003 No existe la variable: HB_CURLOPT_DEFAULT_PROTOCOL
Re: Capturar el motivo del error petición web (curl)
Posted: Sun Nov 06, 2022 1:37 pm
by cnavarro
#define HB_CURLOPT_DEFAULT_PROTOCOL 0x072d00