Hello, everyone. I am working on the mobile multip...
# ktor
n
Hello, everyone. I am working on the mobile multiplatform project and using .ktor on client side (on Android phones). I have following code to send POST requests :
Copy code
protected 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 :
Copy code
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.