Stefan Oltmann
01/01/2024, 10:18 PMval client = HttpClient()
val response: HttpResponse = <http://client.post|client.post>("<http://localhost:8080/upload>") {
contentType(ContentType.Application.OctetStream)
setBody(bytes)
}
fun Application.configureRouting() {
routing {
get("/") {
call.respondText("<http://stefan-oltmann.de|stefan-oltmann.de>")
}
post("/upload") {
val byteArray = call.receiveStream().readBytes()
println("Received bytes: ${byteArray.size}")
val saveGame = SaveGameReader.readSaveGame(byteArray)
val summary = saveGame.createSummary()
call.respondText(summary.toString())
}
}
}
I run into this error:
2024-01-01 23:15:39.439 [eventLoopGroupProxy-4-1] TRACE io.ktor.routing.Routing - Trace for [upload]
/, segment:0 -> SUCCESS @ /
/, segment:0 -> SUCCESS @ /
/(method:GET), segment:0 -> FAILURE "Selector didn't match" @ /(method:GET)
/upload, segment:1 -> SUCCESS @ /upload
/upload/(method:POST), segment:1 -> FAILURE "Selector didn't match" @ /upload/(method:POST)
/health, segment:0 -> FAILURE "Selector didn't match" @ /health
Matched routes:
No results
Route resolve result:
FAILURE "No matched subtrees found" @ /
hallvard
01/02/2024, 7:42 AMPOST
to a GET
endpoint. 🙂Stefan Oltmann
01/02/2024, 9:03 AMpost("/upload")
hallvard
01/02/2024, 10:09 AM/upload/(method:POST), segment:1 -> FAILURE "Selector didn't match" @ /upload/(method:POST)
This seems to have added a trailing slash to your request path. Could be related to that slash or it could be related to the content-type in the headers. I have found ktor to be picky by default, so not choosing xml-handling endpoints for xml-requests if not all headers are OK. Try adding an Accept-header for what the endpoint returns and see if anything changes ...Aleksei Tirman [JB]
01/02/2024, 10:40 AMStefan Oltmann
01/02/2024, 11:54 AMhallvard
01/02/2024, 11:57 AMAccept: **/**
in the ktor client and see if that changes anything?Stefan Oltmann
01/02/2024, 11:59 AMhallvard
01/02/2024, 12:00 PM