Have an application doing a httpPost to Ignition gateway.
The post comes through fine, as I am able to see the ‘doPost’ script execute.
I have also tried request[‘headers’] and I get the headers just fine.
But when I do a request[‘postData’] , the script errors out with a :
""Traceback (most recent call last): File “”, line 8, in doPost KeyError: postData “”
Well I was just saying what the application is posting. The script actually makes no reference to the content-type. I was just mentioning it because it could be relevant information.
The ‘data = request[‘postData’]’ is the code that is failing
See if you can get the request Content-Type header to be application/json (without the ;charset part).
If those headers can't be adjusted, you'll probably need to use the servletRequest object to access the bytes of the post data. (See the Ignition user manual for links to the docs around that object.)
from org.apache.commons.io import IOUtils
from java.lang import String
body = IOUtils.toByteArray(request["servletRequest"].inputStream)
jsonString = String(body, "UTF-8")
data = system.util.jsonDecode(jsonString)
Try this - manually retrieving the request data and parsing it into a JSON string.