Python接口测试-使用requests模块发送post请求
本篇主要记录下使用python的requests模块发送post请求的实现代码.
#coding=utf-8
import unittest
import requests class PostTest(unittest.TestCase): def setUp(self):
host = 'https://httpbin.org/'
endpoint = 'post'
self.url = ''.join([host, endpoint]) def testPost(self):
params = {'show_env':'1'}
json = {
'info': {'show_env': '2', 'sex': 'nv'},
'code': 200,
'a': 'hello', 'b': 'nihao',
'files' : {'file': ('test.txt', 'hello')},
'data': [{'name': 'zhangsan', 'id': '123'}, {'name': 'lisi', 'id': '125'}],
'id': 1900
} r1 = requests.post(self.url,params=params,json=json)
resp1 = r1.json()
print(resp1)
connect = resp1['headers']['Connection']
self.assertEqual(connect, 'close') def tearDown(self):
pass if __name__=='__main__':
unittest.main()
Python接口测试-使用requests模块发送post请求的更多相关文章
- Python接口测试-使用requests模块发送GET请求
本篇主要记录下使用python的requests模块发送GET请求的实现代码. 向服务器发送get请求:无参数时:r = requests.get(url)带params时:r = requests. ...
- python - 怎样使用 requests 模块发送http请求
最近在学python自动化,怎样用python发起一个http请求呢? 通过了解 request 模块可以帮助我们发起http请求 步骤: 1.首先import 下 request 模块 2.然后看请 ...
- python接口测试中—Requests模块的使用
Requests模块的使用 中文文档API:http://2.python-requests.org/en/master/ 1.发送get.post请求 import requests reponse ...
- requests模块发送POST请求
在HTTP协议中,post提交的数据必须放在消息主体中,但是协议中并没有规定必须使用什么编码方式,从而导致了 提交方式 的不同.服务端根据请求头中的 Content-Type 字段来获知请求中的消息主 ...
- python 爬虫 基于requests模块的get请求
需求:爬取搜狗首页的页面数据 import requests # 1.指定url url = 'https://www.sogou.com/' # 2.发起get请求:get方法会返回请求成功的响应对 ...
- Python接口测试,Requests模块讲解:GET、POST、Cookies、Session等
文章最下方有对应课程的视频链接哦^_^ 一.安装.GET,公共方法 二.POST 三.Cookies 四.Session 五.认证 六.超时配置.代理.事件钩子 七.错误异常
- 『居善地』接口测试 — 5、使用Requests库发送POST请求
目录 1.请求正文是application/x-www-form-urlencoded 2.请求正文是raw (1)json格式文本(application/json) (2)xml格式文本(text ...
- Python 爬虫二 requests模块
requests模块 Requests模块 get方法请求 整体演示一下: import requests response = requests.get("https://www.baid ...
- python通过get,post方式发送http请求和接收http响应的方法,pythonget
python通过get,post方式发送http请求和接收http响应的方法,pythonget 本文实例讲述了python通过get,post方式发送http请求和接收http响应的方法.分享给大家 ...
随机推荐
- django环境安装操作整理!
1. Django 下载地址:https://www.djangoproject.com/download/ 注意:目前 Django 1.6.x 以上版本已经完全兼容 Python 3.x. 2.安 ...
- 17flask分页
一,flask_sqlachemy的使用 如果想要展示出来的页面是分页显示,则首先需要知道每页应该分多少个条目,然后通过数据库去查找对应的条数,同时也需要和分页所需的"paginate&qu ...
- hive 下载和导入数据 hive -e
1. 从97导出dim_channel_terminal_flag表数据到txt(数据下载) hive -e 'select * from dim.dim_city' >> dim_cit ...
- 流量控制--3.Linux流量控制的组件
Linux流量控制的组件 流量控制元素与Linux组件之间的相关性: traditional element Linux component 入队列 修订:从用户或网络接收报文 整流 class 提供 ...
- 邻居子系统1.5 neigh output
1.5.1 当邻居项不处于NUD_CONNECTD状态时,不允许快速路径发送报文,函数neigh_resolve_output 用于慢而安全的输出,通常用初始化neigh_ops结构 来实例outpu ...
- Function(函数分享)第二节
一.类型注解 1.1 类型注解 函数的类型注解分为两个部分:参数类型注解和返回值类型注解.其中返回值类型注解有时候我们可以直接省略,因为Typescript可以根据返回的语句来自动判断出返回值的类型. ...
- Linux ---搭建SFTP服务器
在Centos 6.6环境使用系统自带的internal-sftp搭建SFTP服务器. 打开命令终端窗口,按以下步骤操作. 0.查看openssh的版本 ssh -V 使用ssh -V 命令来查看op ...
- uniapp开发小程序
uniapp开发小程序 uni-app 是一个使用 Vue.js 开发所有前端应用的框架,开发者编写一套代码,可发布到iOS.Android.Web(响应式).以及各种小程序(微信/支付宝/百度/头条 ...
- 画echart图时,安卓手机正常,苹果手机上tooltip 在坐标轴下一层
问题: 解决: 在tooltip 中添加如下代码: tooltip:{ position:function(point, params , dom, rect, size){ dom.style.tr ...
- Apache Shiro 反序列化漏洞复现(CVE-2016-4437)
漏洞描述 Apache Shiro是一个Java安全框架,执行身份验证.授权.密码和会话管理.只要rememberMe的AES加密密钥泄露,无论shiro是什么版本都会导致反序列化漏洞. 漏洞原理 A ...