Some of it is most likely usefull in Vip7.3, but other things you will have to do yourself.
The essential part of the example is here:
Code: Select all
predicates
httpPOST : (string Method, jsonObject Params).
clauses
httpPOST(Method, Params) :-
RequestObject = jsonRpcRequest::newNextId(),
RequestObject:method := Method,
RequestObject:params := some(json::o(Params)),
BaseURL = serverUrl_ctl:getText(),
textStatusCell:text := string::format("% ...", BaseUrl),
URL = string::format("%/jsonRpc", BaseUrl),
RequestString = RequestObject:asString(),
stdio::writef("POST %\n", RequestString),
% delayCall to empty the message queue, so the message control receives a WM_PAINT event
delayCall(1, { :- httpPOST2(Url, RequestString) }).
predicates
httpPOST2 : (string Url, string RequestString).
clauses
httpPOST2(URL, RequestString) :-
try
XmlHttp = xmlhttp60::new(),
XmlHttp:open_predicate("POST", URL, comDomains::boolean(false), comDomains::null, comDomains::null),
XmlHttp:setRequestHeader("Content-Type", "application/json-rpc; charset=UTF-8"),
XmlHttp:send(comDomains::string(RequestString)),
handleResponse(XmlHttp)
catch TraceId do
if ComException = exception::tryGetDescriptor(TraceId, exceptionHandling_exception::genericComException) and
unsigned(0x800C0005) = exception::tryGetExtraInfo(ComException, exceptionHandling_exception::hResult_parameter)
then
stdio::writef("Cannot connect to %\n", Url)
else
ExtraInfo = [namedValue("request", string(RequestString)), namedValue("url", string(Url))],
exception::continueDetailed(TraceId, exception::unknown, ExtraInfo)
end if
finally
textStatusCell:text := "",
setAllEnabled(true)
end try.
class predicates
handleResponse : (xmlhttp60 XmlHttp).
clauses
handleResponse(XmlHttp) :-
Hdrs = XmlHttp:getAllResponseHeaders(),
Resp = XmlHttp:responseText,
JsonResp = jsonObject::fromString(Resp),
stdio::writef("HEADERS:\n%\n", Hdrs),
if Error = JsonResp:tryGet_object("error") then
if Code = Error:tryGet_integer("code") then
stdio::writef("Code: %\n", Code)
end if,
if Msg = Error:tryGet_string("message") then
stdio::writef("Message: %\n", Msg)
end if,
if Data = Error:tryGet_string("data") then
stdio::writef("Data: %\n", Data)
else
stdio::writef("Error: %\n", Error:asString())
end if
elseif Result = JsonResp:tryGet_object("result") then
stdio::writef("Result: %\n", Result:asString())
else
stdio::writef("Unexpected response: %\n", Resp)
end if.