• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Answered Sending Json As Form-data

#1
After fighting last week to receive JSON-data via httpGet I ran into the next problem immediatelly. Now I have to send back this modified JSON-data, but it seems that I have to send it back as form-data. How would I do that ?

oRequest = RequestBuilder:post(httpUrl, JsonObject)
:ContentType('application/json')
:AcceptJson()
:Request.
 

Cecil

17+ years progress programming and still learning.
#2
Doing a 'POST' request is of type 'form-data'. The example ABL code you provided looks correct.

Also, try putting the following after the the request to test that is was submitted correctly:

Code:
oResponse = ClientBuilder:Build():Client:Execute(oRequest).
MESSAGE
    oResponse:StatusCode SKIP 
    oResponse:StatusReason SKIP
VIEW-AS ALERT-BOX.
 
Last edited:

Cecil

17+ years progress programming and still learning.
#3
Also, looking at the documenetation there is the following:

AddJson( entity ), AddFormData( data ), WithData( entity ), and WithData( entity, content type ) : Add JSON, Form or other data to the request.
 

Cecil

17+ years progress programming and still learning.
#5
So the form field name (or key) is 'data' and the form field value is a JSON string?
 
#6
i guess yes, but as I said before i'm completely new to this programming. Searching the OpenEdge-documentation, gives me just 1 hit, where "AddFormData" ist only mentioned, nothing more.
So i'm kind of stuck....
 

Cecil

17+ years progress programming and still learning.
#7
i guess yes, but as I said before i'm completely new to this programming. Searching the OpenEdge-documentation, gives me just 1 hit, where "AddFormData" ist only mentioned, nothing more.
So i'm kind of stuck....
Do you have any developer documentation you can share?
 
#8
sorry, the only "documentation" i got was the following email:

a new order can be created with the following link:

Link: http://datapad.it-park.at/projekte/datapad/immoware/datapad2ext.nsf/xp_httpPOST.xsp?u=connect/immoware&p=29immoware29!&anr=12345

Body:
{
"wf_id":"12345",
"wf_nr":"13245",
"wf_bez":"Immoware 12345",
"wf_titel":"Tablet-Übermittlung WF: 12345",
"wf_betreff":"Datapad V1",
"wf_start":"2017-06-30",
"wf_frist":"2017-07-01",
"txtUsername":"test/immoware",
"txtFormID":"4",
"obj_eig_strasse":"Kärntnerstrasse 12",
"obj_eig_name":"Immoware GmbH",
"obj_eig_adresse":"1010 Wien",
"obj_kan_nr":1,
"obj_kli_nr":12,
"obj_ap_telefon":null,
"obj_ap_tel":null,
"obj_ap_email":null,
"Beginndatum":"2017-07-01",
"Ersteller":"Wolfgang Schölmberger"
}
 

Cecil

17+ years progress programming and still learning.
#9
This seems to work.

This code needs to be refactored.

Code:
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 **/
 
Last edited: