import requests
import json
header = {'Content-Type': 'application/json'}
data = {"": ""}
data = json.dumps(data)
endpoint = "http://www.baidu.com/"
request = requests.get(endpoint + "get")
request = requests.head(endpoint + "get")
request = requests.delete(endpoint + "delete")
request = requests.options(endpoint + "options")
request = requests.put(endpoint + "put",data=data)
request = requests.post(endpoint + "post", data=data, headers=header)
request = requests.get(endpoint,verify=False)
request = requests.get(endpoint,timeout=5)
try:
data = str(requests.head('http://www.baidu.com', timeout=5))
except:
print("有问题")
else:
print("没问题")
#打印返回的http状态码
print(request.status_code)
#打印请求的地址
print(request.url)
#json格式打印返回的数据
print(request.json())
#文本格式打印返回的数据
print(request.text)