天天看点

python接口自动化测试(二)-requests.get()

requests常用请求方法使用,包括:get,post

requests库中的Session、Cookie的使用

其它高级部分:认证、代理、证书验证、超时配置、错误异常处理等。

本节首先来了解一下requests库中如何发送get请求:

一、看下方法定义:

python接口自动化测试(二)-requests.get()

2、点击右上角的【source】,看一下它的源码如下:

python接口自动化测试(二)-requests.get()

3、HTTP协议是一个基于请求/响应模式的、无状态的,应用层协议。既然有请求,就有响应,来看下resquest中常用的响应信息:

python接口自动化测试(二)-requests.get()

二、get方法简单使用: 

1、不带参数的get:

python接口自动化测试(二)-requests.get()
python接口自动化测试(二)-requests.get()

输出:

python接口自动化测试(二)-requests.get()
python接口自动化测试(二)-requests.get()

2、 带参数的get:

python接口自动化测试(二)-requests.get()
python接口自动化测试(二)-requests.get()

 输出: 

python接口自动化测试(二)-requests.get()
python接口自动化测试(二)-requests.get()

3、带header的get:

python接口自动化测试(二)-requests.get()
python接口自动化测试(二)-requests.get()

 输出:

4、同时带参数和header:

python接口自动化测试(二)-requests.get()
python接口自动化测试(二)-requests.get()

本文转自贺满博客园博客,原文链接:http://www.cnblogs.com/puresoul/p/7488488.html,如需转载请自行联系原作者。