当前位置:网站首页>Interface test framework practice (I) | requests and interface request construction
Interface test framework practice (I) | requests and interface request construction
2022-04-21 17:59:00 【Hua Weiyun】
Requests Is an elegant and simple Python HTTP library , Actually Python Built in resource module for accessing the network , such as urllib, But it's not as good as Requests Simple and elegant , And it lacks many practical functions . therefore , More recommended to master Requests Interface test practical skills , This is also a popular interface testing tool for Internet manufacturers .
The following is the installation Requests Library starts , Master the interface request structure step by step 、 Interface request assertion 、Schema Assertion 、Json/XML request 、 Test case debugging 、HeadCookie Handle 、Jsonpath application 、 Certification system and other interface testing skills .
pip Command to install Requests.
Requests Official documents :
https://2.python-requests.org/en/master/
Then we'll use the most popular Requests Conduct interface test .
Requests Provides almost everything HTTP Request construction method , And the method of passing in parameters , Customize the configuration of the sent request , It can be used to deal with various request scenarios .
send out get request :
Add... To the request data Parameters , And send the post request :
Add... To the request data Parameters , And send the put request :
send out delete request :
send out head request :
send out options request :
It can also be used directly request function , Introduce different method, For example, use this method to send get request :
The following parameters are not required , But if additional customization of the request is needed , You need to master the functions of the following parameters .
-
header Parameters
By passing in dict Custom request header : -
data Parameters
Send a data sheet encoded as a form : -
files Parameters
Upload files ,dict Format .
Be careful : Binary mode is recommended (binary mode) Open file . This is because Requests May try to provide you with Content-Length header, When it does so , This value will be set to the number of bytes in the file (bytes). If you use text mode (text mode) Open file , There could be mistakes . -
timeout Parameters
Set the timeout ( second ), When this time is reached, it will stop waiting for a response :
Be careful :timeout Only valid for connection process , Nothing to do with the download of the response body .timeout It's not the entire download response time limit , But if the server is timeout No response in seconds , An exception will be thrown ( To be more precise , Is in timeout When no bytes of data are received from the underlying socket within seconds ), If not set timeout, Will be waiting for . -
allow_redirects Parameters
Controls whether redirection is enabled ,bool type , choice True To enable , choice False To disable . -
proxies Parameters
Setting agent ,dict Format ,key The value is the selected protocol , It can be set separately HTTP Request and HTTPS The requested agent . -
verify Parameters
You can pass in bool Value or string, The default is True. If set to False To ignore is to ignore SSL Certificate verification ; On the contrary, verification is needed ; If the pass in value is string Words , Specifies the local certificate as the client certificate .
Pass in the certificate locally :
Ignore right SSL Certificate verification :
Three other important parameters Json、Cookies、Auth It will be introduced in detail in the following chapters .
版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211756229796.html
边栏推荐
- Shell编程学习(三)条件判断、流程控制
- LogStash~LogStash的配置文件
- Do we media sidelines really earn tens of thousands a month? This article is shared without privacy
- 综述:CFD的未来之路
- 每周推荐短视频:企业之间的竞争是看谁能抢占先机
- 为什么基础设施工程师更喜欢MySQL?
- 单片机能做什么,你有什么有单片机或开源硬件做的有意思的作品吗
- Onnx efficiency: comparison with module & dataparallel
- Debugging garbled code of vs2019 visual studio terminal
- Pytorch数据封装进入网络前的几种方式
猜你喜欢

Thesis | attention based bidirectional long short term memory networks for relation classification

Shallow comparison between oceanbase and tidb - implementation plan

The upper computer is fun to play like this!

Pytorch数据封装进入网络前的几种方式

【acwing】166. 数独****(DFS)

VS2019 visual studio 终端调试乱码问题

做自媒体副业真能月入上万?这篇分享,不藏私

MySQL进阶之常用函数

Do we media sidelines really earn tens of thousands a month? This article is shared without privacy

C ODBC loads the files of one folder into the blob column of PostgreSQL database and downloads the blob column to another folder
随机推荐
LogStash~LogStash的工作原理
Shell编程学习(三)条件判断、流程控制
Why do infrastructure engineers prefer MySQL?
AI + clinical trial | Bayer exploration creates "virtual" control group
Logstash ~ configuration file of logstash
一个通用的CommonDialog
[AI and food] a review paper on the latest "dietary assessment based on visual analysis" by the Institute of computing, Chinese Academy of industry and Commerce
将模型训练外包真的安全吗?新研究:外包商可能植入后门,控制银行放款
启牛理财课有用嘛?安全靠谱嘛?
How to get the map value is not so low. There are three ways to get the map parameters
看看项目经理是如何把一个项目带崩的
离散数学 命题逻辑
华为URPF
Logstash ~ filter of logstash
Shell programming learning (III) condition judgment and process control
Finally someone made it clear! It turns out that this is the global one-piece network technology with low delay
Create a local development cluster using k3s
Akismet插件教程WordPress阻止过滤垃圾邮件插件
"Industrial Internet plus safety production" to enhance the safety level of industrial enterprises
LogStash~LogStash的执行模型
