https://kotlinlang.org logo
Title
t

tylerwilson

12/27/2021, 8:01 PM
Ktor 2.0 issue: performing a POST in common code. On Android, I have the same code as before, where I set the contentType in the url { headers { } } section. But running this same code on iOS, I get the following error:
"Header(s) [Content-Type] are controlled by the engine and cannot be set explicitly"
if I try to remove the contentType call on Android, then it fails with
java.lang.IllegalStateException: Fail to serialize body. Content has type: class MyRequest (Kotlin reflection is not available), but OutgoingContent expected.
If you expect serialized body, please check that you have installed the corresponding plugin(like `ContentNegotiation`) and set `Content-Type` header.
So it seems like we cannot do common code in this case. Anybody?
e

e5l

12/27/2021, 8:04 PM
Hey, could you check if you have ContentNegotiation feature installed?
t

tylerwilson

12/27/2021, 8:04 PM
I do:
private val client = HttpClient {
            install(ContentNegotiation) {
                json(parser)
            }
where parser is:
internal val parser = Json { ignoreUnknownKeys = true; isLenient = true; useAlternativeNames = false; }
e

e5l

12/27/2021, 8:06 PM
Could you file an issue with reproducer? I will take a look
t

tylerwilson

12/27/2021, 11:32 PM
Okay, I was finally able to make a small sample that shows the issue: https://youtrack.jetbrains.com/issue/KTOR-3631 Side note: these templates in AS are not the greatest…
I don’t suppose you might be able to take a look at this @e5l? I have tried a few things to work around it, but to no avail. Thank you!
e

e5l

12/30/2021, 2:31 PM
I failed to reproduce it without simulator, so trying to do this with the sample
t

tylerwilson

12/30/2021, 2:38 PM
So sorry, I just saw your work on the issue right after sending the above. Thanks!
e

e5l

12/30/2021, 2:38 PM
No problem
a

Amin Bahiraei

02/28/2022, 12:43 PM
Hi all Any update on that?
e

e5l

02/28/2022, 12:49 PM
Sorry, still in investigation
a

Amin Bahiraei

02/28/2022, 12:51 PM
Is exist any workaround till you fix the bug?
e

e5l

02/28/2022, 12:51 PM
@Aleksei Tirman [JB] could you check?
a

Aleksei Tirman [JB]

03/02/2022, 5:11 PM
The only workaround I see is to use Ktor 1.6.7.
a

Amin Bahiraei

03/05/2022, 7:45 AM
I revert my code to 1.6.7 and it works like a charm.
t

tylerwilson

03/08/2022, 3:21 PM
If this issue is not fixed, I do hope Ktor 1.6.7 will be compatible with Kotlin 1.6.20, or that there will be a 1.6.8 that will be. Thank you.