我在本地(瘦服务器)上运行Rails应用程序,可以从浏览器(本地主机: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
过去这种方法工作正常,但是我最近更新到了Mavericks,我怀疑它可能损坏了某些东西。我也可以从网上成功 curl 。
最佳答案
这是curl bug(a strange one),如果/ etc / hosts中有一个IPv6条目没有响应,则curl不能回落到IPv4。
您可以通过-4
选项强制其使用IPv4。
关于ruby-on-rails - cURL无法连接到本地主机,但浏览器可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20983302/