问题
I'm using ktor 0.9.5. I'm trying a simple example. But when a try to connect to the server i get ERR_EMPTY_RESPONSE. This is my code.
fun main(args: Array<String>) {
embeddedServer(Netty, port = 8080, host = "localhost") {
install(DefaultHeaders)
install(CallLogging)
routing {
get(path = "/") {
call.respondText("Hello World!!")
}
}
}.start()
}
Doing some research I found that changing the project to Maven fix the problem, but because of rules of my organization I can't do it. Any other solution... Thanks before hand.
I have added a println("sometext")
before call.respondText("Hello World!!")
and it's never executed.
回答1:
With ERR_EMPTY_RESPONSE error, I guess you are requesting the server from a Google Chrome browser. Right ? Are you trying to connect to the server from another computer? If so it won't work because you have set the server to only respond for requests coming from localhost.
embeddedServer(Netty, port = 8080, host = "localhost")
Even if you add a println() it won't execute. Try to remove host = "localhost" from embeddedServer() parameters an re-test.
来源:https://stackoverflow.com/questions/52652549/ktor-netty-server-sending-an-empty-response