kotlin - 重定向到 Ktor 中的绝对 URL
问题描述
我正在学习如何使用 ktor。对于特殊用例,我需要从我的 ktor 服务器重定向到不同的域。但是我现在不能让它正常工作。
作为一个简单的例子,我有一个 Application.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/")
推荐阅读
- mysql - 如何获取此查询中重复项的大小?
- uwp - 从 AppxBundle 安装时不显示迁移到 UWP 的 Windows 窗体应用
- angular - 隐藏在某些特定页面中的 Ionic 5 离子标签
- android - 在 android 10 中启动时设置 Activity 崩溃在 android 28<. 如何解决?
- mysql - MYSQL 自动递增日期日期年份
- swift - 以编程方式填充 Swift NSToolBar 时出现问题,项目不可见?
- azure-devops - Azure DevOps 2019 - 仪表板图表不向下钻取
- performance - 正则表达式测试 200 到 299 之间的数字 - 什么更快
- tesseract - 正方体输出中的奇怪符号
- python - FastAPI上传多张图片的请求格式