Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling a webapi with parameters
Message
From
09/03/2018 07:39:31
 
 
To
09/03/2018 07:16:42
General information
Forum:
Visual FoxPro
Category:
Web Services
Miscellaneous
Thread ID:
01658531
Message ID:
01658633
Views:
122
This message has been marked as the solution to the initial question of the thread.
>>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!
>
Good.

A final note. An asynchronous call requires specific control of the status of the response, that is, the .send() method may return without a response from the API being available.
----------------------------------
António Tavares Lopes
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform