python http OPTIONS请

2023-01-31 03:01:23 python http options

通过发送Http OPTioNS请求,可以获取 http允许的方法(我这里主要测试网站是否开启WEBDav),测试如下:

import urllib2
import JSON
import httplib

url='192.168.149.131'
def http_get():
    conn = httplib.HTTPConnection(url)
    conn.request("GET", "/iisstart.htm")
    ret = conn.getresponse()
    response = ret.read() 
    return response

def http_options():
    conn = httplib.HTTPConnection(url)
    conn.request("OPTIONS", "/")
    ret = conn.getresponse()
    print ret.msg.dict
    print ret.msg.dict['allow']

ret = http_options()
#ret2 = http_get()
#print ret

结果如下:

E:\>python isWebDav.py
{'content-length': '0', 'accept-ranges': 'none', 'ms-author-via': 'DAV', 'server': 'Microsoft-IIS/6.0', 'dav': '1, 2', 'dasl': '<DAV:sql>', 'allow': 'OPTIONS, TRACE, GET, HEAD, COPY, PROPFIND, SEARCH, LOCK, UNLOCK', 'cache-control': 'private', 'date': 'Wed, 29 Mar 2017 15:59:20 GMT', 'public': 'OPTIONS, TRACE, GET, HEAD, DELETE, PUT, POST, COPY, MOVE, MKCOL, PROPFIND, PROPPATCH, LOCK, UNLOCK, SEARCH'}
OPTIONS, TRACE, GET, HEAD, COPY, PROPFIND, SEARCH, LOCK, UNLOCK


相关文章