UnderTow无法使用localhost访问

发布于 2021-11-29 11:33:15 字数 946 浏览 990 评论 2

偶然看到Undertow,说试下吧,helloworld就碰到了奇怪的问题。

    public static void main(final String[] args) {
        Undertow server = Undertow.builder()
                .addHttpListener(8080, "localhost")
                .setHandler(new HttpHandler() {
                    @Override
                    public void handleRequest(final HttpServerExchange exchange) throws Exception {
                    	System.out.println("hit "+exchange.getRequestPath());
                        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
                        exchange.getResponseSender().send("Hello World");
                    }
                }).build();
        server.start();
    }

为毛不能使用http://localhost:8080访问呢?

http://127.0.0.1:8080 ok

ping localhost 返回127.0.0.1正常

tomcat跑8080访问http://localhost:8080 正常。

telnet发现如果是localhost就自动关闭连接,哪里需要配置一下吗?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瑾夏年华 2021-12-05 08:24:09

然后 ping localhost 能通么?

回眸一笑 2021-12-04 17:08:31

你 win or linux or mac 的 host 文件里配置 localhost 了么?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文