1、application/x-www-form-urlencoded
这种是使用表单方式提交数据,如图所示,每个参数之间是使用“&”符号进行连接的,打开浏览器进行查看接口请求,可见如下数据,详细编码解释见:Post请求的两种编码格式:application/x-www-form-urlencoded和multipart/form-data
使用python代码发起这样的请求(元数据使用字典格式的数据,然后python3使用urllib.parse.urlencode(testdata)方法进行数据转换,可转换成以上格式,即可发起请求。python2使用urllib.urlencode(testdata)方法即可):
import requests
import json
import urllib
headers={
'Content-Type':'application/x-www-form-urlencoded;charset=utf-8'#multipart/form-data
}
data2={
"testCode": '12',
"testName": 'test'
}
test_url='http://test/test'
response=requests.request(method='post',url=test_url,data=urllib.parse.urlencode(dict(data2)),headers=headers)
# print(response.text)