首页 > 解决方案 > 创建新项目后,Ktor 示例代码未运行

问题描述

我刚刚从idea(2.1.2.4416.7)的内置模板创建了一个ktor项目,当我在控制台中打开网页时出现以下错误:

2021-06-27 12:16:34.158 [main] INFO  ktor.application - Responding at http://0.0.0.0:8080
2021-06-27 12:16:41.583 [eventLoopGroupProxy-4-1] TRACE ktor.application - Failed to decode request
java.lang.IllegalArgumentException: text is empty (possibly HTTP/0.9)
    at io.netty.handler.codec.http.HttpVersion.valueOf(HttpVersion.java:64)
    at io.netty.handler.codec.http.HttpRequestDecoder.createMessage(HttpRequestDecoder.java:95)
    at io.netty.handler.codec.http.HttpObjectDecoder.decode(HttpObjectDecoder.java:249)
    at io.netty.handler.codec.http.HttpServerCodec$HttpServerRequestDecoder.decode(HttpServerCodec.java:123)
    at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:508)
    at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:447)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
    at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.ktor.server.netty.EventLoopGroupProxy$Companion.create$lambda-1$lambda-0(NettyApplicationEngine.kt:251)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:829)

有任何想法吗?它使用 java 版本 11、gradle 版本 7.1 和 kotlin 版本 1.6。

这是 github 上的源代码: https ://github.com/Digital-Nomad/thedrewreport

标签: javakotlinintellij-ideaktor

解决方案


推荐阅读