Nikolai
02/08/2019, 8:37 AMprotected val client = HttpClient {
expectSuccess = false
}
....
protected fun sendPostRequest(requestBody:Any = EmptyContent,
parameters:List<Pair<String, String>> = emptyList(),
requestHeaders:List<Pair<String, String>> = emptyList()) {
GlobalScope.launch(CoroutineContextProvider.provideContext()) {
try {
val call = client.request<HttpResponse> {
url{
protocol = URLProtocol.HTTP
host = serverAddress
encodedPath = requestEncodedPath
}
method = <http://HttpMethod.Post|HttpMethod.Post>
body = requestBody
for (currentPair:Pair<String, String> in requestHeaders) {
headers.append(currentPair.first, currentPair.second)
}
for (currentPair:Pair<String, String> in parameters) {
parameter(currentPair.first, currentPair.second)
}
}
requestResponseHandler(call, call.readText())
} catch (requestException:Exception) {
requestExceptionHandler(requestException)
}
}
}
And I calling this function passing body with json type as parameter :
val body:Any = TextContent(loginData.toString(), contentType = ContentType.Application.Json)
sendPostRequest(body)
Everything working fine, but on Android 4.4.2 content-type of the request is changed to “text/html; charset=iso-8859-1” (according to proxy logs).
I am doing something wrong, or it’s natural behaviour of this Android version?
Thanks.