Ktor Netty Server发送空响应 [英] Ktor Netty Server sending an empty response

查看:162
本文介绍了Ktor Netty Server发送空响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ktor 0.9.5.我正在尝试一个简单的例子.但是当尝试连接到服务器时,我得到了ERR_EMPTY_RESPONSE.这是我的代码.

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()
}

做一些研究,我发现将项目更改为Maven可以解决此问题,但是由于我所在组织的规则,我无法做到这一点.任何其他解决方案...谢谢您.

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.

我在call.respondText("Hello World!!")之前添加了println("sometext"),并且从未执行过.

I have added a println("sometext") before call.respondText("Hello World!!") and it's never executed.

推荐答案

出现 ERR_EMPTY_RESPONSE 错误,我猜您正在从Google Chrome浏览器请求服务器.正确的 ? 您是否要从另一台计算机连接到服务器?如果是这样,它将不起作用,因为您已将服务器设置为仅响应来自本地主机的请求.

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")

即使添加println(),它也不会执行. 尝试从EmbeddedServer()参数中删除 host ="localhost" ,然后重新测试.

Even if you add a println() it won't execute. Try to remove host = "localhost" from embeddedServer() parameters an re-test.

这篇关于Ktor Netty Server发送空响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆