GET
在通过requests.get()进行GET请求时,key1=value1&key2=value2可以写成字典形式在parms中传参
from common.baseRquest import BaseRquest url ='http://10.162.16.5:8072/contents/list' parm = { "contentTypeIds":9001,"_t":"1589279082571" } req.get_requests(url=url,headers=header,params=parm)
POST
在通过requests.post()进行POST请求时,传入报文的参数有两个,一个是data,一个是json;data与json既可以是str类型,也可以是dict类型
1、data为dict时,如果不指定content-type,默认为application/x-www-form-urlencoded,相当于普通form表单提交的形式
2、data为str时,如果不指定content-type,默认为text/plain
3、json为dict时,如果不指定content-type,默认为application/json
4、json为str时,如果不指定content-type,默认为application/json
5、json为a=1&b=2的这种形式时,request.body的内容则为'{"a": 1, "b": 2}'的这种形式
from common.baseRquest import BaseRquest import json url = "http://10.162.16.5:8072/eavIdValue/add" body = {"id": 753, "_t": "1589359027218"} str ="id=753&_t1589359027218" #data - dict #application/x-www-form-urlencoded req.post_requests(url=url,headers=header,data=body) #data - str #application/octet-stream req.post_requests(url=url,headers=header,data=json.dumps(body)) #json - dict req.post_requests(url=url,headers=header,json=body) #json - str #"exception":"com.alibaba.fastjson.JSONException" req.post_requests(url=url,headers=header,json=json.dumps(body)) #data - & #"exception":"com.alibaba.fastjson.JSONException" req.post_requests(url=url,headers=header,json=str)