OK,
// Something like this in PowerBuilder?
RestClient lrc_RestClient
String ls_ResPonse, ls_url, ls_json
JsonGenerator lnv_JsonGenerator
Long ll_RootObject
lrc_RestClient = Create RestClient
lrc_RestClient.SetRequestHeaders("Content-Type:application/json;charset=UTF-8~r~nAccept-Encoding:gzip")
ls_url = "http://localhost:5000/api/D_customers/retrieve"
lnv_JsonGenerator = Create JsonGenerator
ll_RootObject = lnv_JsonGenerator.CreateJsonObject()
lnv_JsonGenerator.AddItemString(ll_RootObject, "company", ls_company)
lnv_JsonGenerator.AddItemNumber(ll_RootObject, "year", li_year)
lnv_JsonGenerator.AddItemDateTime(ll_RootObject, "dateFrom", ldt_datefrom)
lnv_JsonGenerator.AddItemDateTime(ll_RootObject, "dateTo", ldt_dateto)
lnv_JsonGenerator.AddItemString(ll_RootObject, "customerFrom", ls_customerfrom)
lnv_JsonGenerator.AddItemString(ll_RootObject, "customerTo", ls_customerto)
ls_Json= lnv_JsonGenerator.GetJsonString()
//Send Post Request With Json Arguments to the Server
lrc_RestClient.SendPostRequest(ls_url, ls_json, ls_ResPonse)
dwc.ImportJson(ls_response)
// And Something like in SnapDevelop?
// Controller
[HttpPost]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public ActionResult<IDataStore> Retrieve(IDataUnpacker unpacker)
{
var company = unpacker.GetValue<string>("company");
var year = unpacker.GetValue<int>("year");
var dateFrom = unpacker.GetValue<DateTime>("dateFrom");
var dateTo = unpacker.GetValue<DateTime>("dateTo");
var customerFrom = unpacker.GetValue<string>("customerFrom");
var customerTo = unpacker.GetValue<string>("customerTo");
var packer = new DataPacker();
try
{
var result = _id_Customersservice.Retrieve(company, year, dateFrom, dateTo, customerFrom, customerTo);
return Ok(result);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
I want to add:
If there is any sensitive data or these parameters are very complex, a better solution is to call the HTTP POST method to send the parameters in the request body.
You can use the JSONPackage object to combine parameters and get the JSON string on the PB client, and then POST it to your WEB API. You can use the IDataUnpacker type parameter in the WEB API to receive them.
Regards,
Logan