USING OpenEdge.Net.URI.
using OpenEdge.Net.HTTP.IHttpClient.
USING OpenEdge.Net.HTTP.IHttpRequest.
USING OpenEdge.Net.HTTP.IHttpResponse.
USING OpenEdge.Net.HTTP.RequestBuilder.
USING OpenEdge.Net.HTTP.ClientBuilder.
USING Progress.Lang.Object.
USING Progress.Json.ObjectModel.JsonArray.
USING Progress.Json.ObjectModel.JsonObject.
USING Progress.Json.JsonParser.
USING OpenEdge.Net.UriSchemeEnum.
using OpenEdge.Core.String.
DEFINE VARIABLE oURI AS URI NO-UNDO.
DEFINE VARIABLE httpUrl AS CHARACTER NO-UNDO.
DEFINE VARIABLE oRequest AS class IHttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS class IhttpResponse NO-UNDO.
DEFINE VARIABLE oEntity AS class Object NO-UNDO.
DEFINE VARIABLE oJson AS class JsonObject NO-UNDO.
DEFINE VARIABLE userRecordJSON AS LONGCHAR NO-UNDO.
define variable httpClient as IHttpClient no-undo.
log-manager:logging-level = 6.
log-manager:logfile-name = session:temp-dir + 'get_applications.log'.
log-manager:clear-log().
/** Lets Build the JSON object from scratch. In reality, this would
already be available to you from your previous GET request. **/
oJson = NEW JsonObject().
oJson:Add("wf_id", "12345").
oJson:Add("wf_nr", "13245").
oJson:Add("wf_bez", "Immoware 12345").
oJson:Add("wf_titel", "Tablet-Übermittlung WF: 12345").
oJson:Add("wf_betreff", "Datapad V1").
oJson:Add("wf_start", "2017-06-30").
oJson:Add("wf_frist", "2017-07-01").
oJson:Add("txtUsername", "test/immoware").
oJson:Add("txtFormID", "4").
oJson:Add("obj_eig_strasse","Kärntnerstrasse 12").
oJson:Add("obj_eig_name", "Immoware GmbH").
oJson:Add("obj_eig_adresse", "1010 Wien").
oJson:Add("obj_kan_nr", 1).
oJson:Add("obj_kli_nr", 12).
oJson:Add("obj_ap_telefon", integer(?) ). /** NULL **/
oJson:Add("obj_ap_tel", integer(?) ). /** NULL **/
oJson:Add("obj_ap_email", integer(?) ). /** NULL **/
oJson:Add("Beginndatum", "2017-07-01").
oJson:Add("Ersteller", "Wolfgang Schölmberger").
/** Write the JSON objec to a longchar.
'False' option for no formatting. i.e. make a
single long string with not CR & LF */
oJson:write(input-output userRecordJSON, false).
/** Let's build the URL/URI Query String using OPENEDGE classes i.e. http://.....**/
oURI = new URI("http", "datapad.it-park.at").
oURI:Path = '/projekte/datapad/immoware/datapad2ext.nsf/xp_httpPOST.xsp'.
oURI:AddQuery('u', 'connect/immoware').
oURI:AddQuery('p', '29immoware29!').
oURI:AddQuery('anr', '12345').
oRequest = RequestBuilder:Build('POST', oURI )
:AcceptJson() /* As the HTTP client, we accepet messages back in form a JSON */
:AddFormData("data", string(userRecordJSON) ) /** We have to limit the longchar down to 1024 bytes. AddFormData does not allow LongChar datatypes. **/
:Request.
oResponse = ClientBuilder:Build():Client:Execute(oRequest).
/** Debug messages... **/
MESSAGE
"Status Code: " oResponse:StatusCode SKIP
"Status Reason: " oResponse:StatusReason SKIP
"Character Encoding: " oResponse:CharacterEncoding SKIP
"Content Type: " oResponse:ContentType SKIP
"Transfer Encoding: " oResponse:TransferEncoding skip
"Server Response " skip(1)
oResponse:Entity
VIEW-AS ALERT-BOX info.
/** Write the server response to a JSON file..**/
oEntity = oResponse:Entity.
IF TYPE-OF(oEntity, JsonObject) THEN
CAST(oEntity, JsonObject):WriteFile("./postResponce.json", true).
/** NOTE: the Lotus-Domino server is returning the content type and text/html when in fact it's application/JSON **/