cURLはローカルホストに接続できませんが、ブラウザは接続できます。質問する

cURLはローカルホストに接続できませんが、ブラウザは接続できます。質問する

Rails アプリをローカルで実行しています (Thin サーバー)。ブラウザーからローカルに接続できます (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

以前は問題なく動作していましたが、最近 Mavericks にアップデートしたため、何かが壊れているのではないかと考えています。Web からは curl も正常に動作します。

ベストアンサー1

これはカールバグ奇妙なもの) では、/etc/hosts に応答しない IPv6 エントリがある場合、curl は IPv4 にフォールバックできません。

オプションを使用して IPv4 の使用を強制することができます-4

おすすめ記事