# Ignition Script NT Credential Auth Http Post 500 Error Invalid Request Format application/xml

**URL:** <https://forum.inductiveautomation.com/t/ignition-script-nt-credential-auth-http-post-500-error-invalid-request-format-application-xml/103355>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [March 6, 2025, 9:08pm UTC](https://forum.inductiveautomation.com/t/ignition-script-nt-credential-auth-http-post-500-error-invalid-request-format-application-xml/103355 "2025-03-06T21:08:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Drew\_Hitchcock](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@Drew\_Hitchcock](https://forum.inductiveautomation.com/u/Drew_Hitchcock)\
**Post date:** [March 6, 2025, 9:08pm UTC](https://forum.inductiveautomation.com/t/ignition-script-nt-credential-auth-http-post-500-error-invalid-request-format-application-xml/103355/1 "2025-03-06T21:08:29Z")

</div>

I am attempting to perform an HTTP Post on some XML data using domain-based authentication periodically from an Ignition gateway script. My larger task is to run a HTTP get to retrieve tabular data, parse it, update/insert database rows based on the HTTP get result, update a status field in each row of the HTTP get table, and then run a HTTP post on the modified XML HTTP get body. The changes to the HTTP get xml data consisted of replacing values of "SENT" with one of the following values: "SUCCESS", "ERROR: Result is null", or "ERROR: Duplicate LINKID and Sampled Date combination in API call, this row was ignored".

This post contains the code used for the HTTP get: [Script Console cryptography for HttpNtlmAuth requests.get Import Error - Ignition - Inductive Automation Forum](https://forum.inductiveautomation.com/t/script-console-cryptography-for-httpntlmauth-requests-get-import-error/102802/4).

See below for post logic, with dummy values for the function parameters. The XML content is a raw python string, including insignificant whitespace (also tried without insignificant whitespace) with no special encoding. My output with and without insignificant whitespace is as follows:  
{'code': 500, 'body': 'System.InvalidOperationException: Request format is invalid: application/xml.\r\n at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()\r\n at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()\r\n', 'status': HTTP/1.1 500 Internal Server Error}

Since I only modified one string field in each table row as described above, I am pretty sure this is not an issue with my XML content. My suspicions are either character encoding/string entity handling or a server error.

Please advise.

> **HTTP Post Logic**
>
> ```python
> def getNTClient(username, password, domain):
> # Helper function to get http client
> from org.apache.http.auth import NTCredentials, AuthScope
> from org.apache.http.impl.client import HttpClientBuilder, BasicCredentialsProvider
> 	
> credProv = BasicCredentialsProvider() # Build credentials provider
> ntCred = NTCredentials(username, password, '', domain) # Build NT domain credentials
> credProv.setCredentials(AuthScope.ANY, ntCred); # Set credentials
> bld = HttpClientBuilder.create() # Create HttpClientBuilder
> return bld.setDefaultCredentialsProvider(credProv).build() # Build client with credential provider
> 	
> def getResultBody(result):
> from org.apache.http.util import EntityUtils
> return str(EntityUtils.toString(result.getEntity(), 'UTF-8'))
> 	
> def postXml(url, username, password, domain, body):
> from org.apache.http.client.methods import HttpPost
> from org.apache.http.entity import StringEntity
> client	= getNTClient(username, password, domain)
> post	= HttpPost(url)
> post.setEntity(StringEntity(body.encode('utf-8')))
> post.setHeader("Accept", "application/xml")
> post.setHeader("Content-Type", "application/xml")
> post.setHeader("charset", "utf-8")
> res = client.execute(post)
> sts = res.getStatusLine()
> od = {'status' : sts, 'code' : sts.getStatusCode(), 'body' : getResultBody(res)}
> client.close()
> return od
> 
> url = 'MY URL'
> un = 'MY USERNAME'
> do = 'MY DOMAIN'
> pwd = 'MY PASSWORD'
> body	= 'MY XML BODY'
> 
> outpostXml(url, un, pwd, do, body)
> 
> print out
> 
> ```

---

<div class="post-metadata">

**Author:** ![Drew\_Hitchcock](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@Drew\_Hitchcock](https://forum.inductiveautomation.com/u/Drew_Hitchcock)\
**Post date:** [March 7, 2025, 4:47pm UTC](https://forum.inductiveautomation.com/t/ignition-script-nt-credential-auth-http-post-500-error-invalid-request-format-application-xml/103355/2 "2025-03-07T16:47:21Z")

</div>

Apologies for the vague question. Didn't want to share the xml data or some of the parameters in the URL out of concern for client privacy. Resolved it, and posting code so the next guy doesn't have to spend hours figuring this stuff out.

I ended up putting a TaskGuid parameter specific to this API, which I included directly in the URL for the get, and the insignificant whitespace stripped XML body of the post (no special encoding) into a Java ArrayList and then setting the entity of the post as a UrlEncodedFormEntity using the parameters ArrayList. My URL for the get had the form  
https://[host]/[method]?TaskGuid=[getTaskGuid]&Parameters=  
(no "Parameters" in URL) and the URL for my post had the form  
https://[host]/[method]

See updated postXml function. The getNTClient and getResultBody functions stayed the same.

> **Updated postXml Function**
>
> ```python
> def postXml(url, username, password, domain, guid, body):
> # guid: TaskGuid parameter to use for post
> # body: PyString containing XML to use
> 	
> # Import libraries
> from org.apache.http.client.methods import HttpPost
> from java.util import ArrayList
> from org.apache.http.message import BasicNameValuePair
> from org.apache.http.client.entity import UrlEncodedFormEntity
> 	
> client	= getNTClient(username, password, domain) # Construct client
> post	= HttpPost(url) # Construct post
> 	
> params	= ArrayList() # Construct ArrayList
> params.add(BasicNameValuePair('TaskGuid', guid)) # Add TaskGuid parameter to ArrayList
> params.add(BasicNameValuePair('Parameters', body)) # Add Parameters parameter (XML Body) to ArrayList
> post.setEntity(UrlEncodedFormEntity(params)) # Set post entity
> res = client.execute(post) # Execute Post
> sts = res.getStatusLine() # Get status line
> 	
> # Build output dictionary
> od = {'status' : sts, 'code' : sts.getStatusCode(), 'body' : getResultBody(res)}
> client.close()	# Close client
> return od
> 
> ```
