New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html dsl form can not find action url #923

Open
youngxhui opened this Issue Feb 2, 2019 · 0 comments

Comments

Projects
None yet
2 participants
@youngxhui
Copy link

youngxhui commented Feb 2, 2019

Ktor Version

1.1.2

Ktor Engine Used(client or server and name)

netty

JVM Version, Operating System and Relevant Context

jvm 1.8
os windows 10
kotlin 1.3.20

Feedback

I use html dsl create form, but it can not find the action url
this is code

Application.kt

@KtorExperimentalLocationsAPI
@Location("/user")
class User {
    @Location("/login")
    data class UserLogin(val username: String, val password: String)

    @Location("/register")
    data class UserRegister(val username: String, val password: String)
}


fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)

@KtorExperimentalLocationsAPI
@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
    install(Locations)

    routing {
        user()

        get("/") {
            call.respondHtml {
                head {
                    title {
                        +"Ktor 入门"
                    }
                }
                body {
                    a {
                        href = "/register"
                        +"注册"
                    }

                    form("/user/login", method = FormMethod.post, encType = FormEncType.multipartFormData) {
                        input {
                            type = InputType.text
                            name = "username"
                        }
                        br
                        input {
                            type = InputType.password
                            value = ""
                            name = "password"
                        }
                        br
                        input {
                            type = InputType.submit
                            value = "login"
                        }
                    }
                }
            }
        }

        get("/login") {
            call.respond("success")
        }

    }
}
@KtorExperimentalLocationsAPI
fun Route.user() {
    post<User.UserLogin> {
        call.respondText("登录成功")
    }

    post<User.UserRegister> { user ->
        run {
            call.respondText("用户 ${user.username} ${user.password}")
        }
    }
}

in browers ,can not find the url

image

but i used the .http file , can get response

image

@youngxhui youngxhui changed the title html dsl from can not find action url html dsl form can not find action url Feb 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment