io.ktor.http.BadContentTypeFormatException: Bad Content-Type format: content-type: application/json

For some reason calling response.contentType() causes this exception
class ErrorUI (private val response: HttpResponse) {

init {
runBlocking {
println("content type = "+response.contentType()) // <-- exception occures here


// if json
if (response.contentType() == ContentType.Application.Json) {
...
} else {
...
}
class ErrorUI (private val response: HttpResponse) {

init {
runBlocking {
println("content type = "+response.contentType()) // <-- exception occures here


// if json
if (response.contentType() == ContentType.Application.Json) {
...
} else {
...
}
Exception in thread "main" io.ktor.http.BadContentTypeFormatException: Bad Content-Type format: content-type: application/json
at io.ktor.http.ContentType$Companion.parse(ContentTypes.kt:135)
Exception in thread "main" io.ktor.http.BadContentTypeFormatException: Bad Content-Type format: content-type: application/json
at io.ktor.http.ContentType$Companion.parse(ContentTypes.kt:135)
If i change marked line to println( response.headers.get("content-type") ) ill get "application/json" as expected
4 Replies
JavaBot
JavaBot4mo ago
This post has been reserved for your question.
Hey @Tusya <3! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
dan1st
dan1st4mo ago
idk ktor but it seems like this is the issue: https://github.com/ktorio/ktor/issues/1127
GitHub
Content-Type in a request headers · Issue #1127 · ktorio/ktor
Ktor Version 1.1.4 Ktor Engine Used(client or server and name) Apache JVM Version, Operating System and Relevant Context 1.8, macOS Mojave and Linux Mint, IDEA 2019.1.2 CE Feedback I'm accessin...
dan1st
dan1st4mo ago
Stack Overflow
Ktor fails to parse json for api response because of "text/html" co...
I use Ktor (2.3.4) to send an api request to a server that returns json data. Unfortunately, the server put content-type "text/html" instead of "application/json" at headers which
JavaBot
JavaBot4mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server