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
I've also encountered the same issue, and my perspective is 8.1.33. This results in a 401 error for me.
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
{u'Content-Type': [application/json; charset=utf-8], u'User-Agent': [Ignition]}
>>>
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.