HTTP post请求中,body有三种数据格式,处理方式如下:
1、application/json
import requests,json
url = 'http://www.test.com/login'
data = {'user':'Tom','password':'123456'}
jsondata=json.dumps(data)
r =requests.post(url,jsondata)
print(r)
print(r.text)
print(r.content)
2、application/x-www-form-urlencoded:浏览器原生表单
import requests,json
url = 'http://www.test.com/login'
data = {'user':'Tom','password':'123456'}
r =requests.post(url,data)
print(r)
print(r.text)
print(r.content)
3、multipart/form-data:表单格式,可以上传文件
import requests,json
url= 'http://www.test.com/upload'
files = {'file':open('E://test.txt','rb')}
r = requests.post(url,files=files)
print(r)
print(r.text)
print(r.content)
|