http协议:
python3的http模块的四个模块:
client
cookiejar
cookies
server
----------------------------
python3中的http.client模块,python2为httplib模块。
class HTTPConnection
__init__(self, host, port=None,strict=None, timeout=<object object>, source_address=None)
创建一个http连接。
class HTTPSConnection(HTTPConnection)
__init__(self, host, port=None,key_file=None, cert_file=None, strict=None, timeout=<object object>,source_address=None, context=None)
使用ssl建立一个安全的http连接。
HTTPConnection和HTTPSConnection类的方法:
connect():通过host和port建立http连接
close():关闭http连接
send(data):将字节字符串data发送到服务器。
putrequest(method, url, skip_host=0,skip_accept_encoding=0):向服务器发送一个请求
method:
GET:获取文档
PUT:将数据上传到服务器
POST:将数据发送到表单
HEAD:仅返回报头信息
putheader(header, *values):向服务器发送请求报头
header:
Connection
User-Agent
Host
Accept
Accept-Encoding
Accept-Language
Accept-Charset
Content-type
Content-length
endheaders():将空白行发送到服务器表示报头行结束。
request(method, url, body=None, headers={}):将完整的http请求发送到服务器。
getresponse(buffering=False):从服务器获取响应,并返回可以用来服务数据的实例HTTPResponse
class HTTPResponse
__init__(sock, debuglevel=0, strict=0,method=None, buffering=False)
HTTPResponse类的方法:
read(amt=None):从服务器读最多amt个字节。
getheader(name, default=None):从服务器获取响应报头的名称。
getheaders():返回(header, value)元祖的列表
----------------------------
python3中的http.server模块,python2为三个模块:
BaseHTTPSserver、CGIHTTPServer、SimpleHTTP
本文详细介绍了Python3中用于处理HTTP请求和响应的模块,包括client、cookiejar、cookies和server模块,以及它们的核心方法如HTTPConnection和HTTPSConnection。重点讲解了如何使用这些模块进行HTTP连接、请求和响应操作。
8万+

被折叠的 条评论
为什么被折叠?



