wget / curl 是两个比较方便的测试http功能的命令行工具,大多数情况下,测试http功能主要是查看请求响应 头信息 ,而给这两个工具加上适当的命令行参数即可轻易做到,其实查man手册就能找到对应的参数选项,不过这里仍然mark一下。

wget --debug
Turn on debug output, meaning various information important to the developers of

Wget if it does not work properly. Your system administrator may have chosen to

compile Wget without debug support, in which case -d will not work. Please note

that compiling with debug support is always safe—Wget compiled with the debug

support will not print any debug info unless requested with -d.

实例(可以看到,wget链接请求默认采用的是HTTP/1.0协议):

[root@localhost ~]# wget 127.0.0.1 --debug
DEBUG output created by Wget 1.12 on linux-gnu. --2012-05-26 12:32:08-- http://127.0.0.1/
Connecting to 127.0.0.1:80... connected.
Created socket 3.
Releasing 0x09cdfb18 (new refcount 0).
Deleting unused 0x09cdfb18. ---request begin---
GET / HTTP/1.0
User-Agent: Wget/1.12 (linux-gnu)
Accept: */*
Host: 127.0.0.1
Connection: Keep-Alive ---request end---
HTTP request sent, awaiting response...
---response begin---
HTTP/1.1 200 OK
Server: nginx/1.2.0
Date: Sat, 26 May 2012 04:32:08 GMT
Content-Type: text/html
Content-Length: 186
Last-Modified: Fri, 25 May 2012 02:41:59 GMT
Connection: keep-alive
Accept-Ranges: bytes ---response end---
200 OK
Registered socket 3 for persistent reuse.
Length: 186 1
Saving to: “index.html.42” 100%[================================================================>] 186 --.-K/s in 0s 2012-05-26 12:32:08 (4.72 MB/s) - “index.html.42” saved [186/186] [root@localhost ~]#

如果wget不带--debug选项,则可以使用-S、--save-headers选项,不过此时只能查看响应头部信息:
-S

–server-response

Print the headers sent by HTTP servers and responses sent by FTP servers.

–save-headers

Save the headers sent by the HTTP server to the file, preceding the actual contents,

with an empty line as the separator.

实例:

[root@localhost ~]# wget -S 127.0.0.1
--2012-05-26 12:38:32-- http://127.0.0.1/
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Server: nginx/1.2.0
Date: Sat, 26 May 2012 04:38:32 GMT
Content-Type: text/html
Content-Length: 186
Last-Modified: Fri, 25 May 2012 02:41:59 GMT
Connection: keep-alive
Accept-Ranges: bytes
Length: 186 1
Saving to: “index.html.44” 100%[================================================================>] 186 --.-K/s in 0s 2012-05-26 12:38:32 (4.52 MB/s) - “index.html.44” saved [186/186] [root@localhost ~]#

利用curl的-v查看请求响应头部信息:
-v/–verbose

Makes the fetching more verbose/talkative. Mostly useful for debugging. A line

starting with ’>’ means “header data” sent by curl, ’
<
’ means "header data"

received by curl that is hidden in normal cases, and a line starting with ’*’

means additional info provided by curl.

Note that if you only want HTTP headers in the output, -i/--include might be the

option you’re looking for.

If you think this option still doesn’t give you enough details, consider using

--trace or --trace-ascii instead.

This option overrides previous uses of --trace-ascii or --trace.

Use -s/--silent to make curl quiet.

实例(可以看到,wget链接请求默认采用的是HTTP/1.1协议):

[root@localhost aa]# curl -v 127.0.0.1
* About to connect() to 127.0.0.1 port 80 (#0)
* Trying 127.0.0.1… connected
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.19.7 (i686-pc-linux-gnu) libcurl/7.19.7 NSS/3.12.7.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2
> Host: 127.0.0.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/1.2.0
< Date: Sat, 26 May 2012 04:45:12 GMT
< Content-Type: text/html
< Content-Length: 186
< Last-Modified: Fri, 25 May 2012 02:41:59 GMT
< Connection: keep-alive
< Accept-Ranges: bytes
<
<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>
<center><h1>root:web</h1></center>
</body>
</html>
* Connection #0 to host 127.0.0.1 left intact
* Closing connection #0
[root@localhost aa]#

利用curl的-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.

实例:

[root@localhost aa]# curl -I 127.0.0.1
HTTP/1.1 200 OK
Server: nginx/1.2.0
Date: Sat, 26 May 2012 04:43:12 GMT
Content-Type: text/html
Content-Length: 186
Last-Modified: Fri, 25 May 2012 02:41:59 GMT
Connection: keep-alive
Accept-Ranges: bytes [root@localhost aa]#

wget/curl查看请求响应头信息的更多相关文章

  1. curl 查看HTTP 响应头信息

    curl -I "http://baidu.com" 加大写的i参数

  2. HTTP请求响应头信息

    HTTP请求响应头信息 请求:(request) 组成部分: 请求行 请求头 请求体 请求行:请求信息的第一行 格式:请求方式 访问的资源 协议/版本 例如:GET /day0801/1.html H ...

  3. js获取http请求响应头信息

    var req = new XMLHttpRequest(); req.open('GET', document.location, false); req.send(null); var heade ...

  4. HTTP入门(一):在Bash中curl查看请求与响应

    HTTP入门(一):在Bash中curl查看请求与响应 本文简单总结HTTP的请求与响应. 本文主要目的是对学习内容进行总结以及方便日后查阅. 详细教程和原理可以参考HTTP文档(MDN). 本文版权 ...

  5. HTTP状态码、请求方法、响应头信息

    HTTP状态码 当浏览者访问一个网页时,浏览者的浏览器会向网页所在服务器发出请求.当浏览器接收并显示网页前,此网页所在的服务器会返回一个包含HTTP状态码的信息头(server header)用以响应 ...

  6. php设置http请求头信息和响应头信息

    php设置http请求头信息和响应头信息 设置请求服务器的头信息可以用fsockopen,curl组件,header函数只能用来设置客户端响应的头信息,不能设置服务器的头信息. 例子;  一.head ...

  7. 动手学servlet(三) 请求头和响应头信息

    获取请求头信息 package servletdemo; import java.io.IOException; import java.util.Enumeration; import javax. ...

  8. HTTP协议请求头信息和响应头信息

    阅读目录 http的请求部分 常用请头信息 常用响应头信息 http的请求部分 基本结构 请求行 GET  /test/hello.html HTTP/1.1 消息头(并不是每一次请求都一样) 空行 ...

  9. HTTP详解教程 / HTTP 响应头信息 HTTP 响应头信息

    HTTP请求头提供了关于请求,响应或者其他的发送实体的信息. 在本章节中我们将具体来介绍HTTP响应头信息.直线电机哪家好 应答头 说明 Allow 服务器支持哪些请求方法(如GET.POST等). ...

随机推荐

  1. HTML5中Video和Audio

    相关属性 src属性 该属性指定媒体数据的URL地址. autoplay属性 在该属性中指定是否在页面加载后自动播放,使用方法: <video src="test.mov" ...

  2. 如何用meavn构建mahout项目

    (1)下载meavn  解压到D盘

  3. mysql数据库从删库到跑路之mysql数据类型

    一 介绍 存储引擎决定了表的类型,而表内存放的数据也要有不同的类型,每种数据类型都有自己的宽度,但宽度是可选的 详细参考: http://www.runoob.com/mysql/mysql-data ...

  4. php now 5.2 升级5.3

    简单说明 在WIN上有时候需要测试一些PHP程序,又不会自行独立配置环境,那么PHPNow是非常好的选择. PHPNow自带的PHP版本为5.2.14,而最后一次更新在于2010-9-22,PHP5. ...

  5. js自动类型转换

    <script> testeq0 = null == undefined; testeq1 = "0" == 0; //比较前字符串转换为数字 testeq2 = 0 ...

  6. Linux系统——本地定制化yum仓库部署

    1)开启yum仓库配置文件 /etc/yum.conf的keepcache功能 (开启一个新的虚拟机) 将keepcache=0改为1,修改配置文件后重新清空缓存(1默认下载的安装包不删除,才可以实现 ...

  7. 微信小程序组件slider

    表单组件slider:官方文档 Demo Code: var pageData = {} for (var i = 1; i < 5; i++) { (function (index) { pa ...

  8. PKU 3687 Labeling Balls(拓扑排序)

    题目大意:原题链接 给出N个未编号的质量各不相同的球,以及它们质量轻重的大小关系,给它们从1-N贴标签编号,无重复.问是否存在可行的编号方法,不存在输出-1, 如果存在则输出唯一一种方案,此方案是使得 ...

  9. Python3 计算城市距离

    利用上一篇得到的城市经纬度算城市距离 import requests from math import radians, cos, sin, asin, sqrt def geocode(addres ...

  10. IOS开发如何入门

    说到 iOS 开发,自己学得也很浅.不过至少独立一人完成了一个应用的开发到项目上线整个过程.分享一下自己的建议和想法. 首先建议阅读 Start Developing iOS Apps Today,你 ...