# system.net.httpPost is not binary safe

**URL:** <https://forum.inductiveautomation.com/t/system-net-httppost-is-not-binary-safe/11345>\
**Category:** Ignition\
**Created:** [March 10, 2016, 11:14pm UTC](https://forum.inductiveautomation.com/t/system-net-httppost-is-not-binary-safe/11345 "2016-03-10T23:14:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gekkoman](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@gekkoman](https://forum.inductiveautomation.com/u/gekkoman)\
**Post date:** [March 10, 2016, 11:14pm UTC](https://forum.inductiveautomation.com/t/system-net-httppost-is-not-binary-safe/11345/1 "2016-03-10T23:14:06Z")

</div>

Using system.net.httpPost to send arbitrary data is not binary safe.

Only tested on 7.8.2-rc1

From the manual:

[quote]You can post arbitrary data as well, but you’ll need to specify the MIME type. The document is then returned as a string.  
[/quote]

eg sending a 1x1 pixel png by way of example in the attached txt file shows the corruption of the sent data.

[attachment=0]httpPost.txt[/attachment]

For headers and data as indicated in file

```auto
#this works
import urllib2
request = urllib2.Request('http://localhost:8000/add', data=data, headers=headers)
f = urllib2.urlopen(request)
print f.read()

#this corrupts binary data
ret=system.net.httpPost("http://localhost:8000/add", headers['Content-Type'], data)
print ret
```

The application/octet-stream mimetype is intentional in my application.

Quick inspection seems to indicate that it has something to do with the java byte array being a signed value…eg the corruption appears to occur when the value is negative eg over 7bit.

---

<div class="post-metadata">

**Author:** ![jdfrankston](https://avatars.discourse-cdn.com/v4/letter/j/f07891/32.png) [@jdfrankston](https://forum.inductiveautomation.com/u/jdfrankston)\
**Post date:** [August 8, 2016, 7:32pm UTC](https://forum.inductiveautomation.com/t/system-net-httppost-is-not-binary-safe/11345/2 "2016-08-08T19:32:48Z")

</div>

I experienced the same issue. After hexdumping both my original image and the corrupted one I got from the post I realized that the httpPost call is assuming your input string is ISO-Latin1 and converting it to UTF-8 when it posts it. In order to get around this I base64 encoded the image (file) I was sending and decoded it on the server end. I have to say it took me a while to figure it out but I hope this helps someone with the same or similar issue.

_ **Update** _  
For those interested I attached the hexdump for both the corrupted and non corrupted images. (sample was a 1x1 redish orange pixel)
