我正在从Windows批处理运行以下curl命令(在Jenkins作业中,它的价值(:
C:>curl --connect-timeout 240 --user <myuser> --header "Content-Type: text/xml;charset=UTF-8" --data @C:dataOutmyData.xml http://www.myURL.it/myApi.asmx -o C:dataInmtResponse.xml --verbose
当服务器足够快时,一切正常,但偶尔回复很慢,连接超时。
我以为--connect-timeout 240
参数会将连接超时设置为 240 秒(即 4 分钟(,但连接似乎在 20 秒后超时:
0 0 0 0 0 0 0 0 --:--:-- 0:00:20 --:--:-- 0* connect to N.N.N.N port 80 failed: Timed out
完整的输出如下:
C:>curl --connect-timeout 240 --user <myuser> --header "Content-Type: text/xml;charset=UTF-8" --data @C:dataOutmyData.xml http://www.myURL.it/myApi.asmx -o C:dataInmtResponse.xml --verbose
29/06/2020 16:33:06 % Total % Received % Xferd Average Speed Time Time Time Current
29/06/2020 16:33:06 Dload Upload Total Spent Left Speed
29/06/2020 16:33:06
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying N.N.N.N...
29/06/2020 16:33:07 * TCP_NODELAY set
29/06/2020 16:33:07
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:04 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:06 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:07 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:08 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:09 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:10 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:11 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:12 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:13 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:14 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:15 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:16 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:17 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:18 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:19 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:20 --:--:-- 0* connect to N.N.N.N port 80 failed: Timed out
29/06/2020 16:33:27 * Failed to connect to www.myURL.it port 80: Timed out
29/06/2020 16:33:27
0 0 0 0 0 0 0 0 --:--:-- 0:00:21 --:--:-- 0
29/06/2020 16:33:27 * Closing connection 0
29/06/2020 16:33:27 curl: (7) Failed to connect to www.myURL.it port 80: Timed out
29/06/2020 16:33:27
我的卷曲版本如下:
C:>curl --version
curl 7.64.1 (x86_64-pc-win32) libcurl/7.64.1 OpenSSL/1.1.1b (Schannel) zlib/1.2.11 brotli/1.0.7 WinIDN libssh2/1.8.2 nghttp2/1.37.0
Release-Date: 2019-03-27
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile MultiSSL NTLM SPNEGO SSL SSPI TLS-SRP brotli libz
我缺少什么来让 curl 等待服务器至少 240 秒?
您是否尝试过阅读curl
文档?它充满了有趣的事情。
例如,令人惊讶的是,"连接超时"是关于连接到服务器,即检查它是否处于活动状态。它不关心服务器给出其完整响应所需的时间。
由于完整的文档很长,只需放大有关超时的教程:
https://ec.haxx.se/usingcurl/usingcurl-timeouts
永远不要花超过这个钱来连接
curl --connect-timeout 2.37
允许花费
curl --max-time 5.5
的最长时间
传输速度低于此速度意味着退出(固定超时的替代方案(
curl --speed-time 15 --speed-limit 1000