HTTP Server, Content type: application/json

Find and share HowTos to various installations / configurations!
Search

Post Reply
1 post • Page 1 of 1
eraytufan
Posts: 9
Joined: Tue Sep 03, 2019 9:19 am

HTTP Server, Content type: application/json

Post by eraytufan »

Hello all,

I have to create HTTP Server with POST requests that uses content type application/json. Request body consists of JSON body and there aren't request query parameters.

Request body contains the following json:

Code: Select all

{
    "attribute1": 11,
    "attribute2": 22
}
When I used httpConnect for my callback function, I am able to get request parameters inside my callback function, however I cannot access JSON body.

Example:

If I send a request with query parameters additionally with the JSON body I put before, my callback function only returns 2 items `queryAttribute1=33` and `queryAttribute2=44`. 'attribute1' and 'attribute2' values are not returned in the callback function.

http://127.0.0.1:3300/myMethod?queryAtt ... ribute2=44

Code: Select all

cbFunction(dyn_string dsParameter, dyn_string dsValue, const string sUser, const string sIP){

  DebugTN(dsParameter);
  DebugTN(dsValue);
}
Log File:

Code: Select all

WCCOActrl2:2021.05.03 17:10:10.048[dyn_string 2 items
WCCOActrl2:     1: "queryAttribute1"
WCCOActrl2:     2: "queryAttribute2"
WCCOActrl2:]
WCCOActrl2:2021.05.03 17:10:10.048[dyn_string 2 items
WCCOActrl2:     1: "33"
WCCOActrl2:     2: "44"
WCCOActrl2:]

So my question is how can I write a httpConnect with Content type: application/json. Additionally, how can I access body of the request?

p.s.: Code snippet or an example CB function would be a huge help.

Thank you,
Eray

Post Reply
1 post • Page 1 of 1