通过名称连接到本地主机在OS X上显示得慢

我在OS X上运行了一些代码(Perl的WWW :: Mechanize模块),它一直挂在对http://localhost:5000/简单HTTP GET请求上。 我的服务器很好,但响应时间以分钟计。

如果我将其切换到http://127.0.0.1:5000/ ,服务器会立即响应,所以看起来它与使用主机名有关。

这是macOS Sierra,运行版本10.12.1。 /etc/hosts看起来像这样:

 ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost 

我所有的浏览器都可以立即连接,就像wget ,但是curl会得到这个结果:

 $ curl http://localhost:5000/login curl: (7) Failed to connect to localhost port 5000: Connection refused 

但是,如果我切换curl http://127.0.0.1:5000/login ,它工作得很好。