接口测试 - python - requests.post方法中,传参data和json的区别
区别:
1. 使用参数json:不管传str还是dict,如果不指定headers中的content-type,默认都为application/json
请求体如下:
传str:
传dict:
2. 使用参数data:如果不指定content-type,传str时,默认为text/plain;传dict时,默认为application/x-www-form-urlencoded
请求体:
传str:
传dict:
使用参数data时,即使指定content-type为application/json,body的值也是a=1&b=2这种格式
3. 用data参数提交数据时,request.body的内容则为a=1&b=2的这种形式,用json参数提交数据时,request.body的内容则为'{"a": 1, "b": 2}'的这种形式