# \[BUG-16447\] system.net.httpClient : Content-Type header ignored when passing a string as data

**URL:** <https://forum.inductiveautomation.com/t/bug-16447-system-net-httpclient-content-type-header-ignored-when-passing-a-string-as-data/34462>\
**Category:** Ignition\
**Tags:** ignition80, scripting\
**Created:** [May 5, 2020, 8:54pm UTC](https://forum.inductiveautomation.com/t/bug-16447-system-net-httpclient-content-type-header-ignored-when-passing-a-string-as-data/34462 "2020-05-05T20:54:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gage.toschlog](https://avatars.discourse-cdn.com/v4/letter/g/0ea827/32.png) [@gage.toschlog](https://forum.inductiveautomation.com/u/gage.toschlog)\
**Post date:** [May 5, 2020, 8:54pm UTC](https://forum.inductiveautomation.com/t/bug-16447-system-net-httpclient-content-type-header-ignored-when-passing-a-string-as-data/34462/1 "2020-05-05T20:54:44Z")

</div>

It appears the _system.net.httpClient.post_ method ignores Content-Type headers when a string is passed in for the data parameter.

**Script code:**

```auto
client = system.net.httpClient()

serverURL = 'https://ptsv2.com//t/v1wzi-1588711653/post'

testHeaders = {'Content-Type': 'application/x-www-form-urlencoded'}
				
postBody = 'data=testing'

postResponse = client.post(serverURL, None, postBody, headers = testHeaders)

print postResponse.request.headers

```

**Resulting request printed:**

```auto
Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) 
[OpenJDK 64-Bit Server VM (Azul Systems, Inc.)] on java11.0.5

{Content-Type: [text/plain; charset=utf-8], User-Agent: [Ignition]} 

```

---

<div class="post-metadata">

**Author:** ![osolorzano](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/osolorzano/32/6432_2.png) [@osolorzano](https://forum.inductiveautomation.com/u/osolorzano)\
**Post date:** [May 6, 2020, 5:06pm UTC](https://forum.inductiveautomation.com/t/bug-16447-system-net-httpclient-content-type-header-ignored-when-passing-a-string-as-data/34462/2 "2020-05-06T17:06:38Z")

</div>

I was able to replicate this internally and wrote up an internal ticket for it to get fixed in a future version. Sadly, there isn’t much of a workaround for your situation specifically because it will currently always see the body of ‘data=testing’ as a string and will default to making it text/plain.

---

<div class="post-metadata">

**Author:** ![gage.toschlog](https://avatars.discourse-cdn.com/v4/letter/g/0ea827/32.png) [@gage.toschlog](https://forum.inductiveautomation.com/u/gage.toschlog)\
**Post date:** [May 6, 2020, 5:23pm UTC](https://forum.inductiveautomation.com/t/bug-16447-system-net-httpclient-content-type-header-ignored-when-passing-a-string-as-data/34462/3 "2020-05-06T17:23:47Z")

</div>

Understood. Thanks for investigating!

---

<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:** [July 1, 2020, 5:43pm UTC](https://forum.inductiveautomation.com/t/bug-16447-system-net-httpclient-content-type-header-ignored-when-passing-a-string-as-data/34462/4 "2020-07-01T17:43:36Z")

</div>

This is fixed for 8.0.15/the next nightly build.

---

<div class="post-metadata">

**Author:** ![zhang\_rui](https://avatars.discourse-cdn.com/v4/letter/z/59ef9b/32.png) [@zhang\_rui](https://forum.inductiveautomation.com/u/zhang_rui)\
**Post date:** [November 4, 2023, 2:46am UTC](https://forum.inductiveautomation.com/t/bug-16447-system-net-httpclient-content-type-header-ignored-when-passing-a-string-as-data/34462/5 "2023-11-04T02:46:55Z")

</div>

I've also encountered the same issue, and my perspective is 8.1.33. This results in a 401 error for me.

```auto
url = " ************"
token = " *******************************"
headers = {
        "Content-Type": "application/json",
        "Authorization": "Bearer " + token
    }
data = {
         "model": "gpt-3.5-turbo",
         "messages": [{"role": "user", "content": "Say this is a test!"}],
         "temperature": 0.7
       }
client = system.net.httpClient()
    
   
postResponse = client.post(url, data, headers)
print postResponse.request.headers

```

```auto
{u'Content-Type': [application/json; charset=utf-8], u'User-Agent': [Ignition]}
>>> 

```

---

<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:** [November 6, 2023, 4:40pm UTC](https://forum.inductiveautomation.com/t/bug-16447-system-net-httpclient-content-type-header-ignored-when-passing-a-string-as-data/34462/6 "2023-11-06T16:40:51Z")

</div>

I don't see how what you've described relates to the issue described in this thread. A 401 error is an authentication failure, probably not related to the content type...which appears to be correct, anyways; you're sending JSON and it's using a JSON content type.
