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())