Kotlin/Ktor: "closing chunk expected" when requesting a web page

289 Views Asked by At

I'm trying to request a simple HTTP resource in Kotlin using Ktor's client library (1.4.1):

//
// DomainSpecificObjectFactory.kt
//

object DomainSpecificObjectFactory {
    private val client = HttpClient {
        UserAgent("some user agent string")
    }

    suspend fun fromUrl(url: String): DomainSpecificObject = coroutineScope {
        val pageHtml = client.get<String>(url)
        val document = Jsoup.parse(pageHtml)
        val objProps = getDomainSpecificProperties(document)

        DomainSpecificObject(objProps)
    }
}

//
// SomeOtherFile.kt
//

val obj = DomainSpecificObjectFactory.fromUrl("http://example.com/bla")

However, I get this exception:

org.apache.http.ConnectionClosedException: Premature end of chunk coded message body: closing chunk expected

Should I be configuring the HTTP client any differently?

0

There are 0 best solutions below