Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Accessing a Web Service
Message
De
26/10/2017 15:56:40
 
 
À
24/10/2017 09:52:57
Information générale
Forum:
Visual FoxPro
Catégorie:
Web Services
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01655118
Message ID:
01655191
Vues:
132
This message has been marked as the solution to the initial question of the thread.
J'aime (1)
>>>>>Hello, I have to access a web service from my VFP9 desktop application. They gave me a manual, but the examples are in PHP and Python. How can I do it in VFP?
>>>>>
>>>>>I'm attaching images for the PHP (2 images) and Python (1 image) examples.
>>>>>
>>>>>TIA
>>>>
>>>>Those credentials in the images (user and password = 'test') are usable for testing purposes. or were you given others?
>>>
>>>I was given others, of course.
>>

After getting some test credentials (and with no error handling):
LOCAL HTTP AS MSXML2.ServerXMLHTTP60
LOCAL UserLogin AS String
LOCAL UserPassword AS String
LOCAL Guia AS String
LOCAL Reply AS Empty
LOCAL MovementIndex AS Integer
LOCAL Movement AS Object

* a set of programs to work with JSON, by Marco Plaza
LOCFILE("nfjsonread.prg")

* an object to handle the web service consumption
m.HTTP = CREATEOBJECT("MSXML2.ServerXMLHTTP.6.0")

m.UserLogin = "<insert the login, here>"
m.UserPassword = "<and the password, here>"

m.Guia = INPUTBOX("Insert the order that you want to track", "Guia")
* in production, you'll have to make sure the order identification is properly encoded

* set the call to the service
m.HTTP.Open("Get", "http://api.urbano.com.pe:8000/api/tracking/e_tracking/?json={%22guia%22%3A%20%22" + m.Guia + "%22,%22docref%22%3A%20%22%22}", .F.)

m.HTTP.Setrequestheader("Content-type", "application/x-www-form-urlencoded")
m.HTTP.Setrequestheader("user", m.UserLogin)
m.HTTP.Setrequestheader("pass", m.UserPassword)

* send the request, and wait
* you may send the request asynchronously, this will require recoding
m.HTTP.Send()

* ingest the returned information, using Marco's function
m.Reply = nfJsonRead(m.HTTP.Responsetext)

CLEAR

* look at it
? PADR("Order (guia)", 30, "."), m.Reply.array[1].guia
? PADR("Status (estado)", 30, "."), m.Reply.array[1].estado
? PADR("Date (fecha)", 30, "."), m.Reply.array[1].fecha
? PADR("Hour (hora)", 30, "."), m.Reply.array[1].hora
? PADR("Start date (fecha de ingreso)", 30, "."), m.Reply.array[1].f_ingreso
? PADR("Weight (peso)", 30, "."), m.Reply.array[1].peso
? PADR("Items (piezas)", 30, "."), m.Reply.array[1].piezas
? "Movements (movimientos)"

FOR m.MovementIndex = 1 TO ALEN(m.Reply.array[1].movimientos)
	? "#",m.MovementIndex
	m.Movement = m.Reply.array[1].movimientos[m.MovementIndex]
	? PADR("Status (estado)", 30, "."), m.Movement.estado
	? PADR("Sub-Status (sub-estado)", 30, "."), m.Movement.sub_estado
	? PADR("Date (fecha)", 30, "."), m.Movement.fecha
	? PADR("Hour (hora)", 30, "."), m.Movement.hora
ENDFOR
This will result (for a given order number):
Order (guia).................. WYB31912679    
Status (estado)............... ENTREGADO     
Date (fecha).................. 24/10/2017 
Hour (hora)................... 17:41
Start date (fecha de ingreso). 18/10/2017 
Weight (peso)................. 1.26
Items (piezas)................ 1
Movements (movimientos)  
#          1
Status (estado)............... SOLICITUD DE SERVICIO     
Sub-Status (sub-estado)....... Pick Up (File)
Date (fecha).................. 18/10/2017 
Hour (hora)................... 15:20
#          2
Status (estado)............... ADMITIDO EN HUB    
Sub-Status (sub-estado)....... Arribo En Origen
Date (fecha).................. 18/10/2017 
Hour (hora)................... 21:55
#          3
Status (estado)............... DESPACHADO A DESTINO       
Sub-Status (sub-estado)....... Despacho A Destino  
Date (fecha).................. 18/10/2017 
Hour (hora)................... 21:57
#          4
Status (estado)............... ARRIBADO EN DESTINO      
Sub-Status (sub-estado)....... Arribo Agencia (Manual)
Date (fecha).................. 19/10/2017 
Hour (hora)................... 09:25
#          5
Status (estado)............... SALIO A RUTA   
Sub-Status (sub-estado)....... En Ruta 
Date (fecha).................. 20/10/2017 
Hour (hora)................... 00:00
#          6
Status (estado)............... VISITADO  
Sub-Status (sub-estado)....... Coordinacion Posterior
Date (fecha).................. 20/10/2017 
Hour (hora)................... 06:35
#          7
Status (estado)............... SALIO A RUTA   
Sub-Status (sub-estado)....... En Ruta 
Date (fecha).................. 24/10/2017 
Hour (hora)................... 15:45
#          8
Status (estado)............... ENTREGADO     
Sub-Status (sub-estado)....... Entrega Efectiva
Date (fecha).................. 24/10/2017 
Hour (hora)................... 17:41
#          9
Status (estado)............... POD RENDIDO A ORIGEN      
Sub-Status (sub-estado)....... Pod Rendido A Origen  
Date (fecha).................. 24/10/2017 
Hour (hora)................... 18:03
This is just a small subset of the returned information. You'll have to dig into the documentation for the full set.
----------------------------------
António Tavares Lopes
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform