web-dev-qa-db-ja.com

curlを使用してHEADリクエストをハードタイムアウトで実行する

curlを使用してHTTP HEADリクエストをURLに送信し、URLが正しく機能していることを確認します(サーバーが起動しており、正常な応答を送信します)。最後に、返された最終的なHTTP応答コードとURL(すべてのリダイレクトを追跡した後)が必要です。最後に、ハードタイムアウト(リクエストのどこに関係なく、呼び出しが失敗するまでの時間curl is)。

curlはこのすべてをサポートしていますか?これを行うには、どのオプションを使用する必要がありますか?

8
jrdioko

curl -IはHEADリクエストを生成します。

-Lオプションを指定すると、リダイレクトに従います。

タイムアウトは、タイムアウトするリクエストのビットに応じて、いくつかのオプションで制御できます。

man page から:

--connect-timeout <seconds>
          Maximum time in seconds that you allow the connection to the server to take.  This only limits the connection phase, once curl has connected this option is of no more use. See also the -m/--max-time option.

    -m/--max-time <seconds>
          Maximum time in seconds that you allow the whole operation to take.  This is useful for preventing your batch jobs from hanging for hours due to slow networks or links going down.  See also the --connect-timeout option.

タイムアウトに関連する別のオプションもいくつか見る価値があります。

--retry
--retry-delay
--retry-max-time
17
Ladadadada