import requests
url = "http://xxxx"
body = {"name": "zhangsan"}
headers = {"Content-Type": "application/json;charset=utf-8"}
# params 字典类型自动转url编码
response = requests.get(url = url, params=body, headers = headers)
# 以unicode格式返回响应的内容
print(response.text)
# 返回响应码
print(response.status_code)
# 返回字典数据
print(response.json())
response = requests.post(url = url, data = json.dumps(body), headers = headers)
from urllib import parse
headers["content_type"] = "application/x-www-form-urlencoded;charset=utf-8"
response = requests.post(url=url, data = parse.urlencode(body), headers=headers)
原文:https://www.cnblogs.com/test-works/p/15268980.html