sample:resp_info = requests.post(list_url,headers=headers,json=data)
1.传递参数给url:https://httpbin.org/get?key2=value2&key1=value1
payload={'key1':'value1','key2':'value2'}
r=requests.get('https://httpbin.org/get',params=payload)
2.提交一个form表单:
payload={'key1':'value1','key2':'value2'}
r=requests.post("https://httpbin.org/post",data=payload)
The data argument can also have multiple values for each key. This can be done by making data either a list of tuples or a dictionary with lists as values. This is particularly useful when the form has multiple elements that use the same key:
payload_tuples=[('key1','value1'),('key1','value2')]>>> r1=requests.post('https://httpbin.org/post',data=payload_tuples)
payload_dict={'key1':['value1','value2']}
r2=requests.post('https://httpbin.org/post',data=payload_dict)
There are times that you may want to send data that is not form-encoded. If you pass in a string instead of a dict, that data will be posted directly.
For example, the GitHub API v3 accepts JSON-Encoded POST/PATCH data:
>>> importjson>>> url='https://api.github.com/some/endpoint'>>> payload={'some':'data'}>>> r=requests.post(url,data=json.dumps(payload))
3.json:Instead of encoding the dict yourself, you can also pass it directly using the json parameter (added in version 2.4.2) and it will be encoded automatically:
url='https://api.github.com/some/endpoint'>>> payload={'some':'data'}>>> r=requests.post(url,json=payload)