显示允许的HTTP方法

时间:2012-10-14 21:14:28

标签: python http rest methods

我想通过HTTP OPTIONS方法获取允许的HTTP方法,如下所示:

telnet site.com 80
OPTIONS / HTTP/1.0

结果:

HTTP/1.1 200 OK
Date: Sun, 14 Oct 2012 21:04:39 GMT
Server: Apache
Allow: GET,HEAD,POST,OPTIONS
Content-Length: 0
Connection: close
Content-Type: text/html

如何使用Python库进行此操作?

1 个答案:

答案 0 :(得分:2)

import httplib
conn = httplib.HTTPConnection('w3.com')
conn.request('OPTIONS', '/')
response = conn.getresponse()
print response.getheader('allow')

结果是

OPTIONS, TRACE, GET, HEAD, POST