python基础===python3中 http.client 和 urllib的那些事

时间:2022-06-10 06:35:19
import http.client
#python3中没有了 httplib的库
#python 3.x中urllib库和urilib2库合并成了urllib库。。
#其中urllib2.urlopen()变成了urllib.request.urlopen()
# urllib2.Request()变成了urllib.request.Request() http_client = None http_client = http.client.HTTPConnection('localhost',8080,timeout=30) http_client.request('GET','/jenkins/api/json?pretty=true') response = http_client.getresponse()
print(response.status)
print(response.read())

等同于:

import urllib.request

response1 = urllib.request.urlopen("http://localhost:8080/?auto_refresh=true")
print(response1.read())