Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling a webapi with parameters
Message
From
09/03/2018 07:16:42
 
 
To
08/03/2018 10:02:19
General information
Forum:
Visual FoxPro
Category:
Web Services
Miscellaneous
Thread ID:
01658531
Message ID:
01658632
Views:
118
>John, you need to compose the JSON data and post it.
>LOCAL loXMLHTTP as "MSXML2.XMLHTTP"
>loXmlHttp = CREATEOBJECT("MSXML2.XMLHTTP")
>loXmlHttp.open("POST", cdom, .F., cUser, cPassw)

>TEXT TO JSONData NOSHOW
>{ "username": "hbelalcazar@xsoftware.com.co",
> "password": "abcfghz$",
> "client": "companyx"
>}
>ENDTEXT

>loXmlHttp.send(m.JSONData)
>Of course, not only this does not pretend to be real production code, but also you should use a JSON library (besides Rick's, you can also check Marco Plaza's nfJson at VFPX) to write and read the webapi data.

Thank you Antonio and also Mike and Rick, I received some additional help from the provider of the webapi and the final code that worked for me is this:
LOCAL loXMLHTTP as "MSXML2.XMLHTTP", lAsync as Boolean, JSONCred as String
loXmlHttp = CREATEOBJECT("MSXML2.XMLHTTP") 
lAsync=.T. &&asynchronohus
cUser="hbelalcazar@xsoftware.com.co"
cPass="abcfghz$"
cdom="https://xxxtapi.awswebsites.net/api/Internal_list"
JSONCredentials = '{ "username": "hbelalcazar@xsoftware.com.co", "password": abcfghz$", "client": "companyx" }'

loXmlHttp.open("POST", cdom, lAsync) && no need to send user and password here
loXmlHttp.setRequestHeader("Content-type:", "application/json")  && This was the last line added
loXmlHttp.setRequestHeader("Accept:", "application/json") 
loXmlHttp.send(JSONCredentials) &&returns the data OK!
John Harold Belalcázar Lozano
Associate Director Of Development
http://www.belvicto.co/
jhbelalc@gmail.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform