Página 1 de 1

Dois exemplos de web services.

Enviado: 25 Mar 2022 14:48
por Itamar M. Lins Jr.
Olá!
Peguei no grupo internacional.

Código: Selecionar todos

Hola,
Un ejemplo de Get :

******************************************************
#xcommand TRY => BEGIN SEQUENCE WITH {| oErr | Break( oErr ) }
#xcommand CATCH [<!oErr!>] => RECOVER [USING <oErr>] <-oErr->
#xcommand ENDTRY => END

Funct Main()
LOCAL ohttp
LOCAL cUrl:=""
LOCAL JRespuesta:=""
LOCAL Id    
LOCAL Name  
LOCAL eMail

// curl -i -H "Accept:application/json" -H "Content-Type:application/json" -XGET "https://gorest.co.in/public/v2/users"

cUrl    :="https://gorest.co.in/public/v2/posts"
ohttp   := CreateObject( "MSXML2.XMLHTTP" )
ohttp:Open( "GET" ,cUrl,.F.)
ohttp:SetRequestHeader("content-type" , "application/json" )
ohttp:SetRequestHeader("Accept" , "application/json" )
ohttp:SetRequestHeader("Authorization", "Bearer eaa9b2c22c86399d3963f5b240da976927965621ad82bd512b63313e6d66965e" )

TRY
  ohttp:Send()
CATCH
  Alert("No Se pudo Enviar solicitud ")
  return JRespuesta
END
JRespuesta:=ohttp:responseText

Alert("respuesta;"+JRespuesta)

aHasRes := {=>}
hb_jsondecode(JRespuesta ,@aHasRes)

For i := 1 To Len(aHasRes)
   Hb_Alert(aHasRes[i]["id"])
   Hb_Alert(aHasRes[i]["user_id"])
   Hb_Alert(aHasRes[i]["title"])
   Hb_Alert(aHasRes[i]["body"])
Next
RETURN Nil
Usando a CURL Lib do Harbour Linux e Windows.

Código: Selecionar todos

here a SOAP example. I can communicate with a mono webservice either locally
(localhost) or over the network:

------------------------------
#include "hbcurl.ch"
#include "common.ch"
#include "fileio.ch"


function fHttpExecute(cxml)
local endpointUrl,curlHandle,curlErr
local aHeader,chpmserv,cc1

cc1 := ""

cservice := "InformationsService"
caction := "LiefereKernversion"
chpmserv := "localhost"
endpointUrl = "http://"+chpmserv+":22220/"+cservice+".asmx"

aHeader := {}
AADD(aHeader,"Accept-Encoding: gzip,deflate" )
AADD(aHeader,"Content-Type: application/soap+xml;charset=UTF-8")
AADD(aHeader,'action="http://some-website.de/'+caction+'"')

curlHandle := curl_easy_init()

if !empty(curlHandle)

/* Specify the Header data */
curl_easy_setopt(curlHandle,HB_CURLOPT_HTTPHEADER,aHeader)

/* Set the endpoint to send the POST to */
curl_easy_setopt(curlHandle, HB_CURLOPT_URL, endpointUrl)

/* Setup response data */
curl_easy_setopt( curlHandle, HB_CURLOPT_DOWNLOAD )
curl_easy_setopt( curlHandle, HB_CURLOPT_DL_BUFF_SETUP )

/* Specify the POST data */
curl_easy_setopt(curlHandle, HB_CURLOPT_POST, 1)
curl_easy_setopt(curlHandle, HB_CURLOPT_POSTFIELDS, cxml)

/* Do everything */
curlErr := curl_easy_perform(curlHandle)

/* Report any errors */
if empty(curlErr)
/* store response in variable */
cc1 := curl_easy_dl_buff_get( curlHandle )
else
? curl_easy_strerror(curlErr)
endif
else
? "No handle"
endif

if !empty(curlHandle)
/* Clean-up libcurl */
curl_global_cleanup( curlHandle )
else
? "Error"
endif

if empty(cc1)
? "Error"
endif

return cc1
-------------------------

You need to know the exact endpointUrl, the service and action. This information
is contained in the WSDL files. Sometimes it can be hard to get the header lines
in aHeader right so that the webservice accepts the message.
Saudações,
Itamar M. Lins Jr.

Dois exemplos de web services.

Enviado: 25 Mar 2022 22:23
por alxsts
Olá!

Grato por compartilhar.

Sabemos que podemos consumir web services em aplicações [x]Harbour. O problema é criar web services pelo [x]Harbour...

Dois exemplos de web services.

Enviado: 26 Mar 2022 08:21
por Itamar M. Lins Jr.
Olá!
O problema é criar web services pelo [x]Harbour...
Seus "pôbremas se acabaram-se !"
https://github.com/FiveTechSoft/mod_har ... ervice.prg

Código: Selecionar todos

function Main()

   AP_SetContentType( "application/json" )

   ?? hb_jsonEncode( { "Method" => AP_Method(), "Args" => AP_Args(), "Body" => AP_Body() } )

return nil
Saudações,
Itamar M. Lins Jr.

Dois exemplos de web services.

Enviado: 26 Mar 2022 08:25
por Itamar M. Lins Jr.
Olá!
O problema é criar web services pelo [x]Harbour...
Creio que há 4 anos passados, o Rafael Carmona fez um exemplo, com RESTFUL... Tem GIT, VIDEO, Organograma...
https://github.com/rafathefull/restful

Saudações,
Itamar M. Lins Jr.

Dois exemplos de web services.

Enviado: 26 Mar 2022 13:05
por angeiras
Olá,

É fácil demais criar um webservice com:

- mod_harbour 2.0 (já tem a versão 2.1.1)
- Mercury (lib em Harbour para criação das rotas, baseada no modelo MVC e gratuita)

Tem um primeiro exemplo que fiz em https://github.com/neoangeiras/wsdireto

Tudo 100% em Harbour: uma rota (index.prg), uma classe controller e uma classe model. Faltou uma view, mas nesse caso não era necessário

E está também sem autenticação, mas podemos criar um bearer token jwt e autenticar todo o processo.

[]s
Manoel