我是 Kotlin 和 Ktor 的新手,所以我尝试做简单的发布请求。正如你在下面看到的,没有什么特别的。
routing {
post("/articles/add"){
val post = call.receive<ArticleRequest>()
println(post)
}
Run Code Online (Sandbox Code Playgroud)
日志中显示的错误如下,我不明白为什么我应该在这里使用协程。
ERROR Application - Unhandled: POST - /articles/add
java.lang.IllegalStateException: Using blocking primitives on this dispatcher is not allowed. Consider using async channel instead or use blocking primitives in withContext(Dispatchers.IO) instead.
Run Code Online (Sandbox Code Playgroud)
我正在使用 1.4.2 版本。我将不胜感激任何帮助。
如果您使用的是 Jackson,这是一个错误,并且有一个建议的解决方法:
routing {
post("/articles/add") {
with(Dispatchers.IO) {
val post = call.receive<ArticleRequest>()
println(post)
}
}
}
Run Code Online (Sandbox Code Playgroud)
或者您可以回滚到 1.4.1,直到错误解决。
| 归档时间: |
|
| 查看次数: |
785 次 |
| 最近记录: |