Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Accessing a Web Service
Message
De
24/10/2017 11:08:06
 
 
À
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:
01655158
Vues:
96
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.
>>
>>Well, that will explain why I'm getting the message "Ocurrio un error al tratar validar el usuario" in my tests, then.
>
>Is there a way to emulate in VFP9 the result of all those:
>{array...."code"="A123", ...} that are in PHP or Python?

The closest you get to associative arrays in VFP is the Collection object (besides arrays, of course...).

But you don't need that to access the Web Service you're dealing with.

For the JSON part, I would advise to use a JSON VFP library (in VFPX, look at Marco Plaza's nfJson functions: https://github.com/VFPX/nfJson), especially to get the service response. For the rest, calling a HTTP service class (I prefer MSXML2 but you may choose a different one) would be enough:
LOCAL HTTP AS MSXML2.ServerXMLHTTP60

m.HTTP = CREATEOBJECT("MSXML2.ServerXMLHTTP.6.0")

m.HTTP.Open("Get", "http://api.urbano.com.pe:8000/api/tracking/e_tracking/?json=%7B%22guia%22%3A%20" + "1065376072" + ",%22docref%22%3A%20%22%22%7D", .F.)

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

m.HTTP.Send()

? m.HTTP.Responsetext  && this is what you should pass to nfJson
Without actual valid credentials, there is not much I can test than to check for an error reply:
[
   {
      "sql_error":"-1",
      "msg_error":"Ocurrio un error al tratar validar el usuarioexception 'Exception' with message 'Usuario o password invalidos!' in \/sistemas\/weburbano_api\/public_html\/index.php:71\nStack trace:\n#0 {main}"
   }
]
----------------------------------
António Tavares Lopes
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform