Retrive post data in Ctrl Application.

Find and share HowTos to various installations / configurations!
3 posts • Page 1 of 1
Harish
Posts:13
Joined: Fri Nov 11, 2016 8:39 am

Retrive post data in Ctrl Application.

Post by Harish »

I have registered an Url as:

httpConnect("saveDataFromWeb", "/saveDataFromWeb", "application/json");

An analogous function to this Url as below:

string saveDataFromWeb(string sData)
{
DebugTN(__FUNCTION__, sData", sData);

return "";
}

Here is output in Log Viewer:

WCCOActrl2:WCCOActrl (2), 2017.03.02 15:05:12.696, HTTP, reading data from fd = 11
WCCOActrl2:HTTP:read(11):POST /saveDataFromWeb HTTP/1.1
WCCOActrl2:HTTP:read(11):Host: localhost:8079
WCCOActrl2:HTTP:read(11):User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0
WCCOActrl2:HTTP:read(11):Accept: application/json, text/javascript, */*; q=0.01
WCCOActrl2:HTTP:read(11):Accept-Language: en-US,en;q=0.5
WCCOActrl2:HTTP:read(11):Accept-Encoding: gzip, deflate
WCCOActrl2:HTTP:read(11):Content-Type: application/json; charset=utf-8
WCCOActrl2:HTTP:read(11):X-Requested-With: XMLHttpRequest
WCCOActrl2:HTTP:read(11):Referer: https://localhost:8079/
WCCOActrl2:HTTP:read(11):Content-Length: 92
WCCOActrl2:HTTP:read(11):Authorization: Basic
WCCOActrl2:HTTP:read(11):Connection: keep-alive
WCCOActrl2:HTTP:read(11):Pragma: no-cache
WCCOActrl2:HTTP:read(11):Cache-Control: no-cache
WCCOActrl2:HTTP:read(11):
WCCOActrl2:HTTP:read(11):{"fn":"Save01","data":[["UL-S 17000","1","Kessel","0 %","Key123","02.03.2017"]]}
WCCOActrl2:WCCOActrl (2), 2017.03.02 15:05:12.713, HTTP, client user is:"" id:2
WCCOActrl2:2017.03.02 15:05:12.716["saveDataFromWeb"]["sData"]["7B22666E223A224230335F31222C2264617461223A5B5B22554C2D53203137303030222C2231222C224B657373656C77617373657220457264616C6B616C69656E222C22302025222C2220222C2230322E30332E32303137225D5D7D"]
WCCOActrl2:WCCOActrl (2), 2017.03.02 15:05:12.716, HTTP, sent:HTTP/1.1 200 OK
WCCOActrl2:Content-Length: 0
WCCOActrl2:Cache-Control: no-cache
WCCOActrl2:Content-Type: application/json



Question:

In my method "saveDataFromWeb", I get post data as encrypted data. "WCCOActrl2:2017.03.02 15:05:12.716["saveDataFromWeb"]["sData"]"

In Log Viewer at Line "WCCOActrl2:HTTP:read(11):" the posted data is in readable format. How could I retrieve this data in my method "saveDataFromWeb".

I would appreciate any kind of help.

Thank you.

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: Retrive post data in Ctrl Application.

Post by mkoller »

The webserver checks for a "text/*" content type and since the POST message has "application/json", it passes the received data into a blob for the callback function.
(Note: change the argument in your callback).
In this situation you can now only convert the blob manually into a string:

string s;
blobGetValue(b, 0, s, bloblen(b));

Harish
Posts:13
Joined: Fri Nov 11, 2016 8:39 am

Re: Retrive post data in Ctrl Application.

Post by Harish »

Perfect.

Thanks again.

3 posts • Page 1 of 1