方式一:
content-type: form-data
import requestsurl = 'https://baidu.com/'headers = {"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"}data = {"key1":"value1","key2":"value2"}res = requests.post(url=url,headers=headers,data=data)print(res.text)
方式二:
content-type: application/json;charset=utf-8
import requestsimport jsonurl = 'https://baidu.com/'headers = {'content-type': 'application/json;charset=utf-8'}data = {"key1":"value1","key2":"value2"}res = requests.post(url=url,headers=headers,data=json.dumps(data))print(res.text)
方式三:
content-type: application/x-www-form-urlencoded
import requestsfrom urllib.parse import urlencodeheaders = {'content-type':'application/x-www-form-urlencoded',}data = {"key":"value"}url = 'https://www.xxxxx.com'res = requests.post(url=url,headers=headers,data=urlencode(data))print(res.text)
方式四:
content-type: multipart/form-data; boundary=xxx
传送门:用python实现multipart/form-data; boundary=的post请求上传文件