Python3处理HTTP请求的实例
Python3处理HTTP请求的包:http.client,urllib,urllib3,requests
其中,http 比较 low-level,一般不直接使用
urllib更 high-level一点,属于标准库。urllib3跟urllib类似,拥有一些重要特性而且易于使用,但是属于扩展库,需要安装
requests 基于urllib3 ,也不是标准库,但是使用非常方便
个人感觉,如果非要用标准库,就使用urllib。如果没有限制,就用requests
# import http.client
# http_client = http.client.HTTPConnection('localhost',8080,timeout=10)
# http_client.request('get','/jenkins/api/json?pretty=true')
# response = http_client.getresponse()
# print(response.status)
# print(response.read())
# import urllib.request
# response = urllib.request.urlopen('http://localhost:8080/jenkins/api/json?pretty=true')
# print(response.status)
# print(response.read())
# import urllib3
# response = urllib3.PoolManager().request('get','http://localhost:8080/jenkins/api/json?pretty=true')
# print(response.status)
# import requests
# response = requests.get('http://localhost:8080/jenkins/api/json?pretty=true')
# print(response.status_code)
# print(response.text)
# print(response.json())
# print(response.reason)
import requests
from requests.auth import HTTPBasicAuth
response = requests.post('http://localhost:8080/jenkins/job/check_python_version/build',auth=('admin','wangmin'))
print (response.status_code)
print (response.reason)
print(response.headers)
jenkins系统管理=》Configure Global Security,取消勾选“防止跨站点请求伪造”
以上这篇Python3处理HTTP请求的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
以上是 Python3处理HTTP请求的实例 的全部内容, 来源链接: utcz.com/z/313252.html