# Web Dev Module - doPost

**URL:** <https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [August 6, 2020, 7:32pm UTC](https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477 "2020-08-06T19:32:24Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris.Hawkey](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Chris.Hawkey](https://forum.inductiveautomation.com/u/Chris.Hawkey)\
**Post date:** [August 6, 2020, 7:32pm UTC](https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477/1 "2020-08-06T19:32:25Z")

</div>

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 “”

w/ this code:

‘’’ data = request[‘postData’] ‘’’

The content-type is application/j-son.

Any help would be appreciated!!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 6, 2020, 7:36pm UTC](https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477/2 "2020-08-06T19:36:44Z")

</div>

Is there really a dash in your content type? If so, take it out.

---

<div class="post-metadata">

**Author:** ![Chris.Hawkey](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Chris.Hawkey](https://forum.inductiveautomation.com/u/Chris.Hawkey)\
**Post date:** [August 6, 2020, 7:44pm UTC](https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477/3 "2020-08-06T19:44:09Z")

</div>

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

Chris

---

<div class="post-metadata">

**Author:** ![Kevin.McClusky](https://avatars.discourse-cdn.com/v4/letter/k/47e85d/32.png) [@Kevin.McClusky](https://forum.inductiveautomation.com/u/Kevin.McClusky)\
**Post date:** [August 6, 2020, 7:49pm UTC](https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477/4 "2020-08-06T19:49:09Z")

</div>

Your post mentioned the content type is ‘application/j-son’ (with a - in the j-son part).

The Web Dev module should parse the contents of the post into postData only if the header matches one of the following:

application/json (without a dash)  
text/\*

If the headers are anything else, the data won’t show up in postData, and that line of code you mentioned will fail, because postData won’t exist.

---

<div class="post-metadata">

**Author:** ![Chris.Hawkey](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Chris.Hawkey](https://forum.inductiveautomation.com/u/Chris.Hawkey)\
**Post date:** [August 6, 2020, 7:51pm UTC](https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477/5 "2020-08-06T19:51:50Z")

</div>

I see what you are saying.

This is the header response I get

‘{‘Accept’: u’application/json, text/plain, _/_’, ‘User-Agent’: u’axios/0.19.0’, ‘Connection’: u’close’, ‘Host’: u’XX.XX.XX.XX:8088’, ‘Content-Length’: u’408’, ‘Content-Type’: u’application/json;charset=UTF-8’}’

with the exception of the XX’s in the host.

Chris

---

<div class="post-metadata">

**Author:** ![Kevin.McClusky](https://avatars.discourse-cdn.com/v4/letter/k/47e85d/32.png) [@Kevin.McClusky](https://forum.inductiveautomation.com/u/Kevin.McClusky)\
**Post date:** [August 6, 2020, 7:56pm UTC](https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477/6 "2020-08-06T19:56:40Z")

</div>

Yeah, looks like the Content-Type is

> application/json;charset=UTF-8

not

> application/json

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.)

---

<div class="post-metadata">

**Author:** ![Chris.Hawkey](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Chris.Hawkey](https://forum.inductiveautomation.com/u/Chris.Hawkey)\
**Post date:** [August 6, 2020, 8:32pm UTC](https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477/7 "2020-08-06T20:32:09Z")

</div>

Are you referring to the documentation linked here: [HttpServletRequest (Java EE 6 )](https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html)?

As I do not see reference in the SDK guide.

Thanks for your help you two!

FYI, voted for you at ICC2019 😉

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 6, 2020, 8:39pm UTC](https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477/8 "2020-08-06T20:39:00Z")

</div>

> [@Kevin.McClusky](#):
>
> 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.)

Minor note: fixed in 8.0.7 🙂

Does `data = request["data"]` work? There's less special handling for the generic data parameter.

---

<div class="post-metadata">

**Author:** ![Chris.Hawkey](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Chris.Hawkey](https://forum.inductiveautomation.com/u/Chris.Hawkey)\
**Post date:** [August 6, 2020, 9:16pm UTC](https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477/9 "2020-08-06T21:16:32Z")

</div>

Does not like request[“data”] either ☹

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 6, 2020, 9:23pm UTC](https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477/10 "2020-08-06T21:23:23Z")

</div>

```auto
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.

---

<div class="post-metadata">

**Author:** ![Chris.Hawkey](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Chris.Hawkey](https://forum.inductiveautomation.com/u/Chris.Hawkey)\
**Post date:** [August 6, 2020, 9:45pm UTC](https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477/11 "2020-08-06T21:45:40Z")

</div>

object has no attribute ‘inputStream’ ??

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 6, 2020, 10:03pm UTC](https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477/12 "2020-08-06T22:03:33Z")

</div>

Whoops. `request["servletRequest"].inputStream`.

---

<div class="post-metadata">

**Author:** ![Chris.Hawkey](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Chris.Hawkey](https://forum.inductiveautomation.com/u/Chris.Hawkey)\
**Post date:** [August 6, 2020, 11:22pm UTC](https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477/13 "2020-08-06T23:22:57Z")

</div>

Success.  
Thank you very much. 🙂

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 1, 2022, 4:14pm UTC](https://forum.inductiveautomation.com/t/web-dev-module-dopost/37477/14 "2022-06-01T16:14:49Z")

</div>

Split this topic on June 1, 2022, 4:14pm UTC

2 posts were split to a new topic: [500 errors from Webdev](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269)
