【发布时间】:2020-11-01 13:51:03
【问题描述】:
我正在尝试发出 http post 请求,但由于无法理解的原因而失败。
object KtorClient {
val client = HttpClient() {
install(JsonFeature) {
serializer = KotlinxSerializer()
}
}
}
suspend fun createOwner(url : String = "http://localhost:112/company/owner/register", ownerMapper: OwnerMapper) {
println(ownerMapper)
client.post<Unit>(url){
body = ownerMapper
}
}
BlockquoteIllegalStateException {message_8yp7un$_0:“发送正文失败。内容类型:OwnerMapper 类,但应有 OutgoingContent。”,cause_th0jdv$_0:空,堆栈:“captureStack↵Exception↵RuntimeException↵IllegalSta…↵↵↵↵↵ ↵↵↵↵↵↵↵↵↵↵↵↵promiseReactionJob@[native code]”,名称:“IllegalStateException”}
添加序列化插件后,出现此错误:
“找不到类 OwnerMapper 的无参数序列化程序。对于泛型类,例如列表,请显式提供序列化程序。”
我已按照官方示例进行操作,但无法使其运行。正在使用 Kotlin/Js 及以上错误来自浏览器。
【问题讨论】:
标签: ktor kotlin-js ktor-client