使用curl在超时时间内创buildHEAD请求

我想使用curl发送一个HTTP HEAD请求到一个URL来validation它是否正常工作(服务器启动并发送成功的响应)。 最后,我需要返回最终的HTTP响应代码和URL(在redirect之后)。 最后,我需要设置一个硬超时(一段时间之后,调用将失败,无论请求curl在哪里)。

curl是否支持这一切? 我需要使用什么选项来完成这个任务?

curl -I将生成一个HEAD请求。

添加-L选项将使其遵循redirect。

根据您想要超时的请求位,可以使用多个选项来控制超时。

从手册页 :

 --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