Webservice con problemas

Post Reply
User avatar
Adolfo
Posts: 864
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile
Contact:

Webservice con problemas

Post by Adolfo »

Fivewinners.

Tengo una rutina de acceso a unos webservices. Funciona muy bien.

Dentro de ellas tengo una llamada a recuperar unos xml de ventas. El problema con una llamada en especial es que si lo hago directamente por el navegador funciona sin problemas, si lo hago por mi rutina me aparece algo totalmente distinto (un pedazo de codigo de la web, no los datos)

Ya le di muchas vueltas y estoy en el periodo de no saber que puede ser, unos ojos mas tranquilos me podrian ayudar

Code: Select all | Expand

    oOle := CreateObject( 'Microsoft.XMLHTTP' )

    cContentType:="application/json"
    cAuthorization:=""
    cUrl:="https://superboleta.cl/?a=get-ventas&usuario=100428&xml=1&fecha=2024-07-09&key=aq91xQWD81.qw14&new=1"

    oOle:Open( 'GET', cUrl, .f. )

    oOle:SetRequestHeader( "Content-Type",cContentType)
    if !empty(cAuthorization)
        oOle:SetRequestHeader( "Authorization",cAuthorization)
    end if
    oOle:Send(  )
    cRet:=""
    cRet := oOle:ResponseBody
Reduje la rutina a lo mas condensado posible para que la prueben
Pueden probar poniendo el url en su navegador, ver lo que devuelve y compararlo con lo que devuelve la rutina.

Eso, saludos

Desde Chile
Adolfo
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
quim_
Posts: 11
Joined: Tue Jan 07, 2025 11:59 am

Re: Webservice con problemas

Post by quim_ »

Lo que devuelve el web service es un HTML, no un XML
Si lees responseBody o responseText tienes un JSON embebido dentro de un HTML

Code: Select all | Expand

<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></head><body>[...]
Entre las etiquetas <body> y </body> tienes un array/arreglo con todos los datos, sólo tienes que pasar a un hash en harbour y procesar

Code: Select all | Expand

hData := {=>}
hb_jsondecode( responseText, @hData )
Fivewinner desde 1.9, programador PHP y Javascript, PWA & HTML5 evangelista
User avatar
karinha
Posts: 7988
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 6 times
Contact:

Re: Webservice con problemas

Post by karinha »

demora +- 30 minutos para bajar.

Code: Select all | Expand

// C:\FWH..\SAMPLES\LAURENT.PRG - 17/03/2025 - kapiabafwh@gmail.com

#Include "FiveWin.ch"

FUNCTION Main()

   LOCAL oServerWS, cUrl, aArray, x1, erro, oADODBStream, cRetorno
   LOCAL cContentType   := "application/json"
   LOCAL cAuthorization := ""

   cUrl:="https://superboleta.cl/?a=get-ventas&usuario=100428&xml=1&fecha=2024-07-09&key=aq91xQWD81.qw14&new=1"

   #ifdef __XHARBOUR__  // PERFEITO COM XHARBOUR( I Like )

      Try

         Try
            oServerWS := CreateObject( 'MSXML2.XMLHTTP' )
         Catch
            oServerWS := CreateObject( 'Microsoft.XMLHTTP' )
         End

      Catch

         MsgInfo( 'Erro na Criação do Serviço' )

         RETURN NIL

      End

   #else // PERFEITO COM HARBOUR. ( no Like. kkkkk )

      Try

         Try
            oServerWS := win_OleCreateObject( 'MSXML2.XMLHTTP' )
         Catch
            oServerWS := win_OleCreateObject( 'Microsoft.XMLHTTP' )
         End

      Catch

         MsgInfo( 'Erro na Criação do Serviço! Com Harbour', 'Atenção!' )

         RETURN NIL

      End

   #endif

   oServerWS:Open( 'GET', cUrl, .F. )

   oServerWS:SetRequestHeader( "Content-Type", cContentType) // Adolfo

   IF .NOT. EMPTY( cAuthorization )
      oServerWS:SetRequestHeader( "Authorization", cAuthorization )
   ENDIF

   oServerWS:Send()

   IF oServerWS:STATUS != 200

      MsgStop( AllTrim( Str( oServerWS:Status ) ) + " - " + oServerWS:StatusText, "Erro" )

      RETURN NIL

   ENDIF

   WHILE oServerWS:ReadyState != 4

      SYSREFRESH()

      oServerWS:WaitForResponse( 1000 )

   END

   cRetorno := oServerWS:ResponseBody()

   // ? cRetorno

   IF FILE( "ADOLFO.txt" )
      ERASE ADOLFO.txt
   ENDIF

   MemoWrit('ADOLFO.txt', cRetorno)

RETURN NIL

// FIN / END
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Adolfo
Posts: 864
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile
Contact:

Re: Webservice con problemas

Post by Adolfo »

Gracias a ambos, revisare recien hoy, una urgencia me desconecto

Les comento como me va.
Saludos
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Post Reply