横井?
def get():
import http.client
conn = http.client.HTTPConnection("***.***.***.***")
conn.request("GET", "/test.html")
res = conn.getresponse()
print("status:", res.status)
print("reason:", res.reason)
print("headers:", res.getheaders())
print("body:", res.read(300))
def get2():
import urllib.request
req = urllib.request.Request(url="http://***.***.***.***/test.html")
with urllib.request.urlopen(req) as f:
print("status:", f.status)
print("reason:", f.reason)
print("headers:", f.getheaders())
print("body:", f.read(100))
if __name__ == "__main__":
print("----- http.client -----")
get()
print("----- urllib.request -----")
get2()status: 200
reason: OK
headers: [('Date', 'Mon, 31 Aug 2015 03:20:23 GMT'), ('Server', 'Apache/2.2.15 (CentOS)'), (
dified', 'Wed, 08 Jul 2015 15:44:31 GMT'), ('ETag', '"20e28-3f-51a5f03ca0675"'), ('Accept-Ra
bytes'), ('Content-Length', '63'), ('Connection', 'close'), ('Content-Type', 'text/html; cha
-8')]
body: b'<!DOCTYPE html>\n<html>\n<body>\n<h1>test !!</h1>\n</body>\n</html>\n'
status: 200
reason: OK
headers: [('Date', 'Mon, 31 Aug 2015 03:20:23 GMT'), ('Server', 'Apache/2.2.15 (CentOS)'), (
dified', 'Wed, 08 Jul 2015 15:44:31 GMT'), ('ETag', '"20e28-3f-51a5f03ca0675"'), ('Accept-Ra
bytes'), ('Content-Length', '63'), ('Connection', 'close'), ('Content-Type', 'text/html; cha
-8')]
body: b'<!DOCTYPE html>\n<html>\n<body>\n<h1>test !!</h1>\n</body>\n</html>\n'