【发布时间】:2019-12-30 22:37:33
【问题描述】:
我一直在尝试向 ktor 路由中定义的端点发出 GET 请求,但无论我如何尝试获取参数,这些参数似乎都丢失了。根据文档,我应该可以调用call.receive<Parameters>(),这应该会产生一个包含数据的地图,但它总是空的。
到目前为止,我已经尝试安装自己的 ContentNegotiator(从未调用过 convertForReceive 方法),访问 queryParams(也始终为空),并使用始终为空的 call.receiveParameters() 方法
我的 CURL 请求看起来像
curl -X GET \
http://localhost:7802/api/v2/plans \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode "id[starts_with]=asdf"
我的端点看起来像
fun Routing.plans() {
route("plans") {
get("") {
val params = call.receive<Parameters>()
println(params)
call.respond(HttpStatusCode.NoContent)
}
}
}
我希望参数包含 something,但它们始终为空。
【问题讨论】: