khttp
khttp copied to clipboard
Unable to post SOAP messages
It seems like it is impossible to post any sort of XML content via khttp.post
.
On doing the following -
val response = post(
url = soapEndpoint,
headers = mapOf(
"Accept-Encoding" to "gzip,deflate",
"Content-Type" to "text/xml;charset=UTF-8"
),
data = getSoapRequest()
)
I receive an error from the server saying Content-Type
cannot be text/plain
. But, if you look at my POST invocation above, I explicitly set the Content-Type
to be text/xml
.
I suspected that my Content-Type
header was being overwritten somewhere by the khttp library. I investigated into this and I landed up at the following lines of code within the khttp.requests.GenericRequest
class on line 45 -
val DEFAULT_DATA_HEADERS = mapOf(
"Content-Type" to "text/plain"
)
And on line 134
if (json == null) {
this.data = data
if (data != null) {
mutableHeaders += GenericRequest.DEFAULT_DATA_HEADERS
}
}
So it does seem like your Content-Type header always ends up being over-written in case you're posting XML content.
Thank you for helping with the code investigation!
Looking in to get a fix.
@bbeaupain I need this in something that I'm using at the moment. Would you be happy for me to take this up and fix it?