常用的有两种传入数据的模式,一种是参数模式,一种是json数据模式
1 参数格式
import requests
params = {"data": "g"}
url = "http://10.6.8.2:1990/post"
headers = {"Content-type": "application/x-www-form-urlencoded;charset=utf-8"}
r = requests.post(url, data=params, headers=headers)
jsonData = r.json()
jsonData
# data = get_argument("data")
2 json格式
url = "http://10.6.8.2:1990/post"
json_data = {
'data':"q"
}
headers = {"Content-type": "application/json", "Connection": "close"}
r = requests.post(url, data=json.dumps(json_data), headers=headers)
jsonData = r.json()
# data = json.loads(self.request.body.decode('utf-8'))