【问题标题】:Error while executing GET request (Unhandled: GET)执行 GET 请求时出错(未处理:GET)
【发布时间】:2021-05-12 13:47:48
【问题描述】:

我尝试执行 GET 请求,但收到此错误。

这里的Bug很明显,但我不知道是什么问题。

suspend fun getNotesForUser(email: String) = notes.find(Note::owners contains email).toList()

这是路线代码

route("/getNotes") {
    authenticate {
        get {
            val email = call.principal<UserIdPrincipal>()!!.name
            val notes = getNotesForUser(email)
            call.respond(OK, notes)
        }
    }
}

笔记类:

data class Note(
val title: String,
val content: String,
val date: Long,
val owners: List<String>,
val color: String,
@BsonId
val id: String = ObjectId().toString()

我所有的 POST 请求都在工作,但这个 GET 没有。

【问题讨论】:

    标签: web backend ktor


    【解决方案1】:

    ktor docsauthentication 插件给出了以与您指定的方式不同的方式布置路由器的示例。示例代码:

    routing {
        authenticate("myauth1") {
            get("/authenticated/route1") {
    ...
    

    但是在您的代码中,您传递的路线如下:

    route("/getNotes") {
        authenticate {
            get {
    ...
    

    您可以尝试在get 而不是route 中指定路线的方法吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-05
      • 2019-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-01
      相关资源
      最近更新 更多