jrd*_*oko 8 http url timeout http-headers curl
我想使用curl向 URL 发送 HTTP HEAD 请求以验证它是否正常工作(服务器已启动并发送成功响应)。最后,我需要返回的最终 HTTP 响应代码和 URL(在遵循任何重定向之后)。最后,我需要设置一个硬超时(一段时间后调用将失败,无论请求curl位于何处)。
是否curl支持这一切?我需要使用哪些选项来完成此操作?
Lad*_*ada 17
curl -I 将生成一个 HEAD 请求。
添加该-L选项将使其遵循重定向。
可以使用多个选项控制超时,具体取决于您要超时的请求位。
从手册页:
--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.
Run Code Online (Sandbox Code Playgroud)
另外几个与超时相关的选项也值得一看:
--retry
--retry-delay
--retry-max-time
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15221 次 |
| 最近记录: |