Hi guys I am trying to get ktor http client to POST a request to an API with FormURLEncoded. I am getting the following error:
io.ktor.http.UnsafeHeaderException: Header Content-Type is controlled by the engine and cannot be set explicitly
Here is my data class:
data class getAuth(
val client_id: String,
val client_secret: String,
val grant_type: String = "client_credentials",
val scope: String = "NSMS"
)
Here is my constructor:
val message =
client.post<Unit> {
url(URL("
https://tapi.telstra.com/v2/oauth/token"))
contentType(ContentType.Application.FormUrlEncoded)
body = getAuth(client_id = "overriddenkey", client_secret = "overridenpass")
}
Is there something I am missing here? How do I go about sending the POST with Content-Type: application/x-www-form-urlencoded ?