3

我想使用 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 库做到这一点?

4

1 回答 1

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

结果是

OPTIONS, TRACE, GET, HEAD, POST
于 2012-10-15T02:24:55.673 回答