Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1185391
  • 博文数量: 233
  • 博客积分: 6270
  • 博客等级: 准将
  • 技术积分: 1798
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-26 08:32
文章分类

全部博文(233)

文章存档

2011年(31)

2010年(202)

我的朋友

分类: 系统运维

2010-05-24 23:07:39

HEAD方法

(Head方法)要求响应与相应的GET请求的响应一样,但是没有的响应体(response body)。这用来获得响应头(response header)中的元数据信息(meta-infomation)有(很)帮助,(因为)它不需要传输所有的内容

验证方法:

>>> conn = httplib.HTTPConnection('')
>>> conn.request('head', '/index.html')
>>> r1 = conn.getresponse()
>>> print r1.status, r1.reason
200 OK

>>> print r1.read()

Traceback (most recent call last):
  File "", line 1, in
    print r1.read()
  File "C:\Python26\lib\httplib.py", line 524, in read
    s = self._safe_read(self.length)
  File "C:\Python26\lib\httplib.py", line 619, in _safe_read
    raise IncompleteRead(''.join(s), amt)
IncompleteRead: IncompleteRead(0 bytes read, 18801 more expected)  <====== 此处异常表示没有数据

>>> print r1.getheaders()
[('content-length', '18801'), ('x-cache', 'HIT from xd33-86.HP08040025.sina.com.cn'), ('x-powered-by', 'mod_xlayout_jh/0.0.1vhs.markIII.remix'), ('accept-ranges', 'bytes'), ('expires', 'Tue, 06 Oct 2009 12:49:13 GMT'), ('vary', 'Accept-Encoding'), ('server', 'Apache/2.0.63 (Unix)'), ('last-modified', 'Wed, 16 Sep 2009 09:18:13 GMT'), ('connection', 'close'), ('x-ua-compatible', 'IE=EmulateIE7'), ('cache-control', 'max-age=60'), ('date', 'Tue, 06 Oct 2009 12:48:13 GMT'), ('content-type', 'text/html')]

验证结果:成功

 

GET方法

(Get方法用来)请求指定的资源。它是目前网上最常用的方法。它不应该用于一些会造成副作用的操作中(在网络应用中用它来提交动作是一种常见的错误用法)

验证方法:

>>> conn = httplib.HTTPConnection('')

>>> conn.request('get', '/index.html')
>>> r1 = conn.getresponse()
>>> print r1.status, r1.reason
200 OK
>>> print r1.read()

(打印出 ' 的内容)

验证结果:成功

阅读(1376) | 评论(0) | 转发(0) |
0

上一篇:HTTP的POST方法

下一篇:HTTP options方法

给主人留下些什么吧!~~