jbe*_*eck 29 curl ruby-on-rails thin osx-mavericks
我在本地运行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
Run Code Online (Sandbox Code Playgroud)
这曾经工作得很好,但我最近更新到小牛队,我怀疑可能已经破坏了一些东西.我也可以从网上成功卷曲.
Mar*_*ins 22
代替
curl localhost:3000
Run Code Online (Sandbox Code Playgroud)
尝试
curl 0.0.0.0:3000
Run Code Online (Sandbox Code Playgroud)
有用.
如果没有,请在启动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
Run Code Online (Sandbox Code Playgroud)
使用第2行末尾的url而不是 ENV['HOST']
假设您没有触及 /etc/hosts 并且 scutil 报告是肯定的:
$ scutil -r 127.0.0.1
Reachable,Local Address
$ scutil -r localhost
Reachable,Local Address
Run Code Online (Sandbox Code Playgroud)
那么我的猜测是防火墙处于活动状态并且不接受来自curl 的连接。
尝试将curl添加到接受的应用程序列表中(我猜测语言替代方案,因为我的机器设置为使用瑞典语)首选项-->安全-->防火墙替代方案-->加号-->(搜索curl和添加它)
注意:确保添加您在 shell 中实际使用的卷曲。
$ type -a curl
curl is /opt/local/bin/curl
curl is /usr/bin/curl
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18918 次 |
| 最近记录: |