重定向至Ktor中的绝对URL



我正在研究如何使用ktor。对于特殊用例,我需要从我的 ktor 服务器重定向到不同的域。但是我现在无法让它严格工作。

作为一个简单的例子,我有一个应用程序.kt

import io.ktor.application.*
import io.ktor.http.*
import io.ktor.response.*
import io.ktor.routing.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
fun main(args: Array<String>) {
val server = embeddedServer(Netty, port = 8080) {
routing {
get("/") {
call.respondRedirect("www.google.com")
}}
}
}
server.start(wait = true)

}

我除了的是它将我重定向到www.google.com但它将我重定向到localhost:8080/www.google.com

想通了。您还需要设置协议。这行得通

call.respondRedirect("https://google.com/")

最新更新