Max*_*Max 12 curl http wget head http-headers
我已经通过CLI使用了定时某些HTTP请求time和工具,如wget和curl,如下所示:
/usr/bin/time -v wget --spider http://localhost/index
/usr/bin/time -v curl http://localhost/index 2>&1 > /dev/null
我注意到的是,在使用时curl,我得到的响应时间与wget第一次请求时的响应时间相似,后续请求的响应次数要少得多,就好像响应curl是从缓存中提供的而wget不是.
在调查之后,我发现在指定时--spider,wget发出一个HEAD附加的请求,这可以解释为什么缓存被绕过wget:
请求
HEAD /index HTTP/1.0
User-Agent: Wget/1.12 (linux-gnu)
Accept: */*
Host: localhost
Connection: Keep-Alive
Run Code Online (Sandbox Code Playgroud)
响应
HTTP/1.1 200 OK
Date: Mon, 28 Nov 2011 14:45:59 GMT
Server: Apache/2.2.14 (Ubuntu)
Content-Location: index.php
Vary: negotiate,Accept-Encoding
TCN: choice
X-Powered-By: PHP/5.3.2-1ubuntu4.10
Set-Cookie: SESS421aa90e079fa326b6494f812ad13e79=16oqmug3loekjlb1tlvmsrtcr2; expires=Wed, 21-Dec-2011 18:19:19 GMT; path=/
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Mon, 28 Nov 2011 14:45:59 GMT
Cache-Control: store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
Run Code Online (Sandbox Code Playgroud)
因为我正在做更高级的东西(在单独的文件中编写正文和标题,发布数据,在jar中保存cookie ...)我需要使用curl而不是wget.因此,我正试图模仿一个HEAD请求curl.
我设法发送如下HEAD请求curl:
curl "http://localhost/index" --request "HEAD" -H "Connection: Keep-Alive" -0
请求
HEAD /index HTTP/1.0
User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
Host: localhost
Accept: */*
Connection: Keep-Alive
Run Code Online (Sandbox Code Playgroud)
响应
HTTP/1.1 200 OK
Date: Mon, 28 Nov 2011 15:44:02 GMT
Server: Apache/2.2.14 (Ubuntu)
Content-Location: index.php
Vary: negotiate,Accept-Encoding
TCN: choice
X-Powered-By: PHP/5.3.2-1ubuntu4.10
Set-Cookie: SESS421aa90e079fa326b6494f812ad13e79=4001hcmhdbnkb9e2v8nok9lii1; expires=Wed, 21-Dec-2011 19:17:22 GMT; path=/
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Mon, 28 Nov 2011 15:44:02 GMT
Cache-Control: store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
Run Code Online (Sandbox Code Playgroud)
尽管请求/响应似乎没问题,但当我curl在嗅探时执行上述命令时,tcpdump我可以看到服务器直接响应,但是我的curl命令总是保持挂起15秒,这显然是一个大问题,因为我正在尝试时间我的curl命令(前一天,我曾经得到一个curl: (18) transfer closed with 3 bytes remaining to read服务器没有HEAD正确处理,并返回Content-Length: 3没有返回任何内容,但没有一切看起来没问题).
我尝试使用--max-time和--speed-time参数curl在收到后立即暂停,200 OK但没有任何区别.
问:如何HEAD以curl命令从服务器收到响应后立即停止的方式发送curl请求?
fle*_*esk 22
你为什么不用这个-I选项?
-I/--head
(HTTP/FTP/FILE) Fetch the HTTP-header only! HTTP-servers feature
the command HEAD which this uses to get nothing but the header
of a document. When used on a FTP or FILE file, curl displays
the file size and last modification time only
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6982 次 |
| 最近记录: |