菜鸟笔记
提升您的技术认知

python 技术篇-ag真人游戏

新的 python 已经由 httplib 包变成了 http.client
所以如果还引入 httplib 库就会报错:modulenotfounderror: no module named 'httplib'

import http.client
httpclient = http.client.httpconnection('10.10.xx.xx',5554)
# 发送请求,直接用参数/,相当于直接访问ip 端口号
httpclient.request('get','/')
# 获取请求
response = httpclient.getresponse()
# 分解response回应消息
print("status:" str(response.status))
# print(response.reason)
# print(response.read())
print('-'*5 'headers' '-'*5)
print(response.getheaders())
print('-'*5 'message' '-'*5)
print(response.msg)

执行代码后结果如下:

status:200
-----headers-----
[('accept-ranges', 'bytes'), ('etag', 'w/"93-1589209308000"'), ('last-modified',
 'mon, 11 may 2020 15:01:48 gmt'), ('content-type', 'text/html'), ('content-leng
th', '93'), ('date', 'thu, 06 aug 2020 13:23:28 gmt'), ('server', 'server')]
-----message-----
accept-ranges: bytes
etag: w/"93-1589209308000"
last-modified: mon, 11 may 2020 15:01:48 gmt
content-type: text/html
content-length: 93
date: thu, 06 aug 2020 13:23:28 gmt
server: server
网站地图