Ktor 2.0 issue: performing a POST in common code. ...
# ktor
t
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:
Copy code
"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
Copy code
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
Hey, could you check if you have ContentNegotiation feature installed?
t
I do:
Copy code
private val client = HttpClient {
            install(ContentNegotiation) {
                json(parser)
            }
where parser is:
Copy code
internal val parser = Json { ignoreUnknownKeys = true; isLenient = true; useAlternativeNames = false; }
e
Could you file an issue with reproducer? I will take a look
t
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
I failed to reproduce it without simulator, so trying to do this with the sample
t
So sorry, I just saw your work on the issue right after sending the above. Thanks!
e
No problem
a
Hi all Any update on that?
e
Sorry, still in investigation
a
Is exist any workaround till you fix the bug?
e
@Aleksei Tirman [JB] could you check?
a
The only workaround I see is to use Ktor 1.6.7.
a
I revert my code to 1.6.7 and it works like a charm.
t
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.