Ktor Netty Server sending an empty response

时光毁灭记忆、已成空白 提交于 2019-12-13 03:52:56

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!