Garrison Henkle
01/15/2024, 5:30 PMGarrison Henkle
01/15/2024, 5:30 PMEncountered unknown error: io.ktor.client.call.NoTransformationFoundException: Expected response body of the type 'class <my data class annotated with @Serializable> (Kotlin reflection is not available)' but was 'class io.ktor.utils.io.ByteBufferChannel (Kotlin reflection is not available)'
In response from `<my url>`
Response status `400 `
Response header `ContentType: text/plain`
Request header `Accept: application/json`
Garrison Henkle
01/15/2024, 5:33 PMHttpClient(OkHttp) {
install(ContentNegotiation) {
json(json = inject())
}
install(HttpTimeout)
}
Chrimaeon
01/15/2024, 5:35 PMChrimaeon
01/15/2024, 5:35 PMGarrison Henkle
01/15/2024, 5:38 PMGarrison Henkle
01/15/2024, 5:49 PM<http://client.post|client.post> {
method = <http://HttpMethod.Post|HttpMethod.Post>
url(urlString = "$apiBaseUrl$ENDPOINT_PATH")
contentType(type = ContentType.Application.Json)
setBody(body = request)
setCookie(name = "uuid_guest", value = requestData.guestId)
}
Chrimaeon
01/15/2024, 5:56 PMsetCookie
you just add to the the headers via https://ktor.io/docs/request.html#cookiesGarrison Henkle
01/15/2024, 6:34 PMcookie
function that does the header stuff under the hood:
private fun HttpMessageBuilder.setCookie(
name: String,
value: String,
) {
val now = Clock.System.now().toEpochMilliseconds()
cookie(
name = name,
value = value,
expires = GMTDate(timestamp = now + NINETY_DAYS_MS),
domain = apiCookieDomain,
secure = true,
httpOnly = false,
)
}
Garrison Henkle
01/15/2024, 6:36 PM<http://client.post|client.post> {
method = <http://HttpMethod.Post|HttpMethod.Post>
url(urlString = "$apiBaseUrl$ENDPOINT_PATH")
contentType(type = ContentType.Application.Json)
setBody(body = request)
cookie(
name = "uuid_guest",
value = requestData.guestId,
expires = GMTDate(timestamp = now + NINETY_DAYS_MS),
domain = apiCookieDomain,
secure = true,
httpOnly = false,
)
}
Garrison Henkle
01/15/2024, 6:55 PM