thinBasic_MSXML2 enables thinBasic programmer to use selected MS XML 2.0 objects.
ServerXMLHTTPRequest module class implements MS IServerXMLHTTPRequest interface.
DOMDocument module class implements MS IXMLDOMDocument interface.
PowerBASIC for Windows, v10.04
- Default compiler Win32 API headers used
- COM interfaces generated by PowerBASIC COM Browser
Clone module_core in a way it is placed in the same root directory as this project.
Connect and download some JSONs
Uses "MSXML2"
Uses "Console"
'---Reference for Fake JSon: http://jsonplaceholder.typicode.com/
Dim oHTTP As new ServerXMLHTTPRequest
printl "IsObject:", oHTTP.IsObject
printl "IsNothing:", oHTTP.IsNothing
oHTTP.SetTimeOuts(60000, 60000, 60000, 60000)
'------------------------------------------------------------
' Users
'------------------------------------------------------------
printl "---Users---" in %CColor_fYellow
oHTTP.Open("GET", "http://jsonplaceholder.typicode.com/users", %FALSE)
oHTTP.Send
PrintL "Status:", oHTTP.Status, "(" & oHTTP.Statustext & ")"
PrintL oHTTP.ResponseText
'------------------------------------------------------------
' Single Post
'------------------------------------------------------------
printl "---Single Post---" in %CColor_fYellow
oHTTP.Open("GET", "http://jsonplaceholder.typicode.com/posts/1", %FALSE)
oHTTP.Send
PrintL "Status:", oHTTP.Status, "(" & oHTTP.Statustext & ")"
PrintL oHTTP.ResponseText
'------------------------------------------------------------
' All Posts
'------------------------------------------------------------
printl "---All Posts---" in %CColor_fYellow
oHTTP.Open("GET", "http://jsonplaceholder.typicode.com/posts", %FALSE)
oHTTP.Send
PrintL "Status:", oHTTP.Status, "(" & oHTTP.Statustext & ")"
PrintL oHTTP.ResponseText
PrintL
WaitKey
Connect to a bank exposing some REST API and make requests sending headers
Uses "MSXML2"
Uses "Console"
uses "File"
Dim oHTTP As new ServerXMLHTTPRequest
oHTTP.SetTimeOuts(60000, 60000, 60000, 60000)
'------------------------------------------------------------
' Get account movements in Sync mode
'------------------------------------------------------------
printl "---Get account movements Sync---" in %CColor_fYellow
oHTTP.Open("POST", "https://sandbox.platfr.io/api/banking/v1/accounts/movementslist")', %FALSE)
oHTTP.setRequestHeader ("Content-Type", "application/json; charset=utf-8")
oHTTP.Send(" {""accountNumber"": ""7652XX380XX18"", ""startdate"": ""01/01/2017"", ""enddate"": ""06/01/2017""} ")
PrintL "Status:", oHTTP.Status, "(" & oHTTP.Statustext & ")"
PrintL oHTTP.ResponseText
file_save(app_sourcepath & "AccountMovements.json", oHTTP.ResponseText)
printl oHTTP.getAllResponseHeaders
printl "Content-Type:", oHTTP.getResponseHeader("Content-Type")
PrintL
'------------------------------------------------------------
' Get account movements in ASync.
' With ASync you need to test oHTTP.ReadyState till it is %ServerXMLHTTP_COMPLETED
'------------------------------------------------------------
printl "---Get account movements ASync---" in %CColor_fYellow
oHTTP.Open("POST", "https://sandbox.platfr.io/api/banking/v1/accounts/movementslist", %TRUE)
oHTTP.setRequestHeader ("Content-Type", "application/json; charset=utf-8")
oHTTP.Send(" {""accountNumber"": ""7652XX380XX18"", ""startdate"": ""01/01/2017"", ""enddate"": ""06/01/2017""} ")
PrintL
print "State:"
while oHTTP.ReadyState <> %ServerXMLHTTP_COMPLETED
print "[" & oHTTP.ReadyState & "]"
sleep 40
Wend
PrintL
PrintL "Status:", oHTTP.Status, "(" & oHTTP.Statustext & ")"
PrintL oHTTP.ResponseText
PrintL
'------------------------------------------------------------
' Get account balance in Sync mode
'------------------------------------------------------------
printl "'---Get account balance Sync---" in %CColor_fYellow
oHTTP.Open("POST", "https://sandbox.platfr.io/api/banking/v1/balance/getbalance", %FALSE)
oHTTP.setRequestHeader ("Content-Type", "application/json; charset=utf-8")
oHTTP.Send(" {""accountNumber"": ""7652XX380XX18""} ")
PrintL "Status:", oHTTP.Status, "(" & oHTTP.Statustext & ")"
PrintL oHTTP.ResponseText
WaitKey