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

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

Script code:

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:

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]} 
1 Like

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.

Understood. Thanks for investigating!

This is fixed for 8.0.15/the next nightly build.

2 Likes