我在本地运行Rails应用程序(瘦服务器),我可以从浏览器本地连接(localhost:3000),但是当我尝试使用curl时,我得到:
curl -H 'id:1' -i 'http://localhost:3000/api/data' -v * Hostname was NOT found in DNS cache * Trying ::1... * Adding handle: conn: 0x7fd121808200 * Adding handle: send: 0 * Adding handle: recv: 0 * Curl_addHandleToPipeline: length: 1 * - Conn 0 (0x7fd121808200) send_pipe: 1, recv_pipe: 0 * Connection failed * connect to ::1 port 3000 failed: Connection refused * Trying fe80::1... * Connection failed * connect to fe80::1 port 3000 failed: Connection refused * Failed to connect to localhost port 3000: Connection refused * Closing connection 0 curl: (7) Failed to connect to localhost port 3000: Connection refused
这曾经工作得很好,但我最近更新到小牛队,我怀疑可能已经破坏了一些东西.我也可以从网上成功卷曲.
这是一个卷曲错误(一个奇怪的错误),如果/ etc/hosts中的IPv6条目没有响应,则curl无法回退到IPv4.
您可以通过该-4
选项强制它使用IPv4 .
代替
curl localhost:3000
尝试
curl 0.0.0.0:3000
有用.
如果没有,请在启动rails服务器时检查输出:
=> Booting WEBrick => Rails 3.2.13 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2014-10-28 15:30:08] INFO WEBrick 1.3.1 [2014-10-28 15:30:08] INFO ruby 2.0.0 (2014-02-24) [x86_64-darwin12.5.0] [2014-10-28 15:30:08] INFO WEBrick::HTTPServer#start: pid=4004 port=3000
使用第2行末尾的url而不是 ENV['HOST']