natario1
03/28/2022, 11:04 PMcontentType(ContentType.Image.JPEG)
setBody(byteArray)
But in 2.0, I get a 500 error. Has anything changed with respect to this?Aleksei Tirman [JB]
03/29/2022, 8:16 AMbody
property is replaced with the setBody
method.natario1
03/29/2022, 12:10 PMAleksei Tirman [JB]
03/29/2022, 12:16 PMnatario1
03/29/2022, 2:04 PMval ktor = ktorClient
val image = imageFile.readBytes()
<http://ktor.post|ktor.post>(serverUrl) {
contentType(ContentType.Image.JPEG)
setBody(thumb)
}
natario1
03/29/2022, 2:05 PMimage/jpeg
which I explicitly set, to application/octet-stream
. This didn’t happen in 1.X and also does not happen if I don’t apply the content negotiation pluginnatario1
03/29/2022, 2:15 PMAleksei Tirman [JB]
03/29/2022, 3:24 PMContent-Type
header with the value application/octet-stream
is sent even when the ContentNegotiation
plugin is installed:
import io.ktor.client.*
import io.ktor.client.engine.apache.*
import io.ktor.client.plugins.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
suspend fun main() {
val client = HttpClient(Apache) {
install(ContentNegotiation) {
json()
}
}
val r = <http://client.post|client.post>("<https://httpbin.org/post>") {
contentType(ContentType.Application.OctetStream)
setBody(ByteArray(1024))
}.bodyAsText()
println(r)
}
natario1
03/29/2022, 3:27 PMAleksei Tirman [JB]
03/29/2022, 3:28 PMnatario1
03/29/2022, 3:29 PMAleksei Tirman [JB]
03/29/2022, 3:29 PMApache
engine.Aleksei Tirman [JB]
03/29/2022, 3:52 PMnatario1
03/29/2022, 3:54 PM