1、get方法:
payload={
"name":"lhys.notNeed"
}
r=requests.get('http://zj.gcjs.zdvictory.com/unionpro/unionpro/ignorecheck/sysPara/findByName',params=payload)
print(r.text)
post方法:
1、application/x-www-form-urlencoded格式
import requests
datas = {"param1": "Detector", "param2": "cnblogs"}
r = requests.post("http://httpbin.org/post", data=datas)
print(r.text)
print(r.status_code)
2、 application/json格式
import json
import requests
headers = {'Content-Type': 'application/json'}
datas = json.dumps({"param1": "Detector", "param2": "cnblogs"})
r = requests.post("http://httpbin.org/post", data=datas, headers=headers)
print(r.text)
3、text/xml数据格式
请求数据这样:
<?xml version="1.0"?>
<methodCall>
<methodName>examples.getStateName</methodName>
<params>
<param>
<value><i4>41</i4></value>
</param>
</params>
</methodCall>
参考Python实现
import requests
headers = {"Content-Type": "text/xml"}
datas = """<?xml version="1.0"?>
<methodCall>
<methodName>examples.getStateName</methodName>
<params>
<param>
<value><i4>41</i4></value>
</param>
</params>
</methodCall>"""
r = requests.post("http://httpbin.org/post", data=datas, headers=headers)
print(r.text)
4、multipart/form-data数据格式(含文件上传)
import requests
files = {"file": open("C:/Users/Administrator/Desktop/test.txt", "rb")}
r = requests.post("http://httpbin.org/post", files=files)
print(r.text)
5、headerS构造
headers={
"Content-Type":"application/json",
"charset":"UTF-8"}
r=requests.get(url,params=payload,headers=headers)
6、cookies构造
?
7、xml请求
|