Python发送四种格式的post请求的代码样例
2024-08-24 10:07:05
x-www-form-urlencoded:
path = "/api/v1/topics/update"
params={'accesstoken':'d38a77f0-6f29-45cd-8d49-f72f15b98fd2','topic_id':'5c89021773798770589936b0','title':'hahaha','tab':'share','content':'hahaha'}
response_text = requests.post(url=self.url+path, data=params).text # 将响应内容转换成字典格式
response_dict = json.loads(response_text)
# 获取response message字段的值
response_message = response_dict['topic_id']
# 判断message的值
self.assertEqual(response_message, '5c89021773798770589936b0', msg='topic返回值不对')
form-data:
# post request method
response = requests.post(url=url + path, params=params,headers=headers)
# Is the return status code 200?
self.assertEqual(response.status_code, 200, msg="The status code is not 200")
# Is the return message SUCCESS?
response_text = requests.post(url=url + path, params=params,headers=headers).text
# Convert response content into dictionary format.
response_dict = json.loads(response_text)
# Gets the value of the response message.
response_message = response_dict['message']
# Determine the value of message.
self.assertEqual(response_message, 'SUCCESS', msg='The response message is not SUCCESS')
#Print response text.
print(response.text)
最新文章
- 《HeadFirst SQL》笔记
- SpringMVC自定义处理器里的那些事
- 7-RandomAccessFile 随机流
- CSS样式覆盖顺序
- scp: command not found如何解决
- iOS - (集成支付宝SDK大坑总结)
- iOS开发--控件
- MySQL中DATE_FORMATE函数内置字符集解析
- MYSQL基础笔记(一)
- ActiveMQ 的安装
- php上传图片到server
- Python-数据类型-转摘
- hdu 5591 BestCoder Round #65(博弈)
- 编译内核时出现drivers/mfd/mxc-hdmi-core.c:36:24: fatal error: mach/clock.h: No such file or directory
- HTTP与HTTPS对访问速度(性能)的影响
- 关于Select2下拉框组件
- Beta冲刺随笔汇总
- Node操作MongoDB并与express结合实现图书管理系统
- 事务的ACID性质
- SparkSQL简介
热门文章
- learn python the hard way 习题18~25总结
- 质控工具之TrimGalore使用方法
- Mac必备神器之Go2Shell
- JavaScript动态加载资源
- android -------- Data Binding的使用 RecyclerView
- android -------- 混淆打包报错(warning - InnerClass annotations are missing corresponding EnclosingMember annotations)
- Vue音乐项目笔记(四)(搜索页面提取重写)
- mac下 配置homebrew 和java home
- Parking Lot CodeForces - 480E
- JQ 实现监测input中值的变化并绑定到另个input