Is there an example of Post method of #Prim_web.Httprequest?

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Taku Izumi
Posts: 35
Joined: Thu Dec 15, 2016 2:03 pm

Is there an example of Post method of #Prim_web.Httprequest?

Post by Taku Izumi » Thu Jan 13, 2022 11:43 am

Hi,

I want to post an excel file selected from the file picker control to an external website using the #prim_web.Httprequest.
There are examples in the manual and xDemoWebWeather, but both are examples of the Get method and I couldn't find an example of the Post method.

Please let me know if anyone has an example.
In particular, I would like to know how to overwrite headers and create form data.

Regards,
Taku Izumi

User avatar
Dino
Posts: 188
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: Is there an example of Post method of #Prim_web.Httprequest?

Post by Dino » Fri Jan 14, 2022 3:30 am

Ohayou Taku Izumi!

There is an example web page XDEMO_126 which makes a PUT instead of a POST, but the concept should be the same. I created this example based on that to access a url in jsontest.com

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_WEB) Theme(#SYS_THEME<MaterialDesignBlue>)

Define_Com Class(#PRIM_LIST) Name(#List) ColumnHeaderHeight(48) ColumnLines(False) DisplayPosition(1) Height(388) Left(32) Parent(#COM_OWNER) RowHeight(48) TabPosition(1) Top(37) Width(1161)
Define_Com Class(#PRIM_LIST.String) Name(#ListColumn1) ColumnWidth(1) DisplayPosition(1) Parent(#List) SortOnClick(True) Source(#STD_NVARC) CellWidth(0) ColumnUnits(Proportion)
Define_Com Class(#STD_INT) Name(#HttpStatus)

Evtroutine Handling(#Com_owner.Initialize)
#COM_OWNER.TestAPost
Endroutine

Mthroutine Name(TestAPost)
* Define_Com Class(#Prim_Web.HttpRequest) Name(#PostTest) Url("http://ip.jsontest.com/") Method(POST)
*  http://validate.jsontest.com/?json={"key":"value"}
Define_Com Class(#Prim_Web.HttpRequest) Name(#PostTest) Url('http://validate.jsontest.com/?json={"three":"san"}') Method(POST)

Define_Com Class(#PRIM_WEB.Json) Name(#Json)
Define_Com Class(#prim_web.JsonElement) Name(#JRoot_Element) Reference(*Dynamic)

Define_Com Class(#PRIM_WEB.JsonObject) Name(#JsonObject) Reference(*Dynamic)
#JsonObject <= #Json.CreateRootObject
#JsonObject.InsertString Key("one") String("ichi")
#JsonObject.InsertString Key("two") String("ni")
#PostTest.Content := #Json

#PostTest.ExecuteAsync

Evtroutine Handling(#PostTest.Completed)
#STD_NVARC := ('Completed')
Add_Entry To_List(#List)

#HttpStatus := #PostTest.Response.StatusCode
#Json := #PostTest.Response.Content
#JRoot_Element <= #Json.RootItem

#STD_NVARC := #HttpStatus.AsString
Add_Entry To_List(#List)
If (#HttpStatus = 200)
#STD_NVARC := #PostTest.Response.Content.Text
Add_Entry To_List(#List)
Else
#STD_NVARC := #PostTest.Response.StatusText
Add_Entry To_List(#List)
Endif
Endroutine

Evtroutine Handling(#PostTest.Failed)
#Sys_web.Alert Caption("Post Failed")
Endroutine
Endroutine
End_Com

Post Reply