0

I understand that reading actual query string params is made easy with the get_arg function. However, I am not seeing anything in the examples or documentation that will let me read the POST payload. In my case, it's a JSON encoded string. Parsing the JSON is easy enough once I can actually address it.

Does anyone have an example that shows how to read the raw POST payload in C?

Gil
  • 3,279
  • 1
  • 15
  • 25
Mike Keen
  • 171
  • 1
  • 4
  • 12

1 Answers1

1

Found the answer by just walking argv[]. Turns out it's as easy as:

char *raw_payload = (char*)argv[0];
Mike Keen
  • 171
  • 1
  • 4
  • 12
  • 1
    FYI, G-WAN has some [JSON APIs](http://gwan.com/api#json) that may help, now that you know where to reference the POST payload. And the [entity.c](http://gwan.com/source/entity.c) example may also help a bit. – Kenigmatic Jan 27 '16 at 20:34
  • @Mike: the **get_arg** function fetches the query parameters of both GET and POST requests. G-WAN does it transparently for you. +1 for having answered your own question. – Gil Jan 28 '16 at 14:29
  • @Gil the only issue with get_arg is that as far as I can see, it can only get named parameters. I couldn't work out a way of using it to get an unnamed payload. – Mike Keen Jan 28 '16 at 16:15
  • @Mike, you are right. Hence the **argv[]** alternative that we provided for the other cases (and some other scripting languages than C) and the direct ***entity = (char*)get_env(argv, REQ_ENTITY);** method depicted in entity.c – Gil Jan 29 '16 at 17:13