Http.onrequest() question

i want to POST json data to the imp agent. is there a function to parse the .body into a jsondecode() compatible string? i could use regexp if it’s implemented on the agent side.

I think this might be what your looking for

jsondecode wants a valid json string. i think the POST body needs processing to make a json string. the post body still has %5B’s,%5D’s,& etc. the httpin node will accept a json post and return a json table.

is there an http.configure() function for .onrequest() to tell it to expect json?

i’m sending data to the agent with the same $ajax() call i used for the httpin node, so i think the agent is receiving valid json.

i just printed the body headers, it’s not json. i’ll work on that and report back.

Ok, I don’t understand http headers. The content-type needs to be content-type application/x-www-form-urlencoded, and the data sent from ajax needs to “stringified”, then it comes through properly, and jsondecode() accepts it.

Me neither but a believe Javascript .stringify converts values to JSON object also would expect the content-type to be application/json

I tried it POSTing using application/json with and without stringify. I received an empty body both ways.

One for Peter & others more knowledgeable

It’s hard to say much without seeing an example body, but if it’s URL-encoded (with all the %5B stuff) and JSON-encoded, what you want is something like:
fields <- http.urldecode(body); mytable <- http.jsondecode(fields.value);
except that it might be fields.(something-else) depending on exactly what’s in the body.


it’s working well without specifying any content-type and stringifying the data first.