当前位置:网站首页>Interface test framework practice (I) | requests and interface request construction
Interface test framework practice (I) | requests and interface request construction
2022-06-27 00:40: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 .
边栏推荐
- 滑环安装有哪些技巧和方法
- “message“:“Bad capabilities. Specify either app or appTopLevelWindow to create a session“
- 能在手机上开户炒股吗 网上开户炒股安全吗
- 直播回顾 | 子芽&CCF TF:云原生场景下软件供应链风险治理技术浅谈
- Kubeadm create kubernetes cluster
- Pet hospital management system based on SSMP
- Reading graph augmentations to learn graph representations (lg2ar)
- Lambda表达式
- [test] the content of the hottest test development learning route has been updated again to help pass the customs and open the test of large factories
- 目标追踪拍摄?目标遮挡拍摄?拥有19亿安装量的花瓣app,究竟有什么别出心裁的功能如此吸引用户?
猜你喜欢

Lambda表达式

冲刺强基计划数学物理专题二

Why does EDR need defense in depth to combat ransomware?

Redis detailed tutorial

国内外最好的12款项目管理系统优劣势分析
![Cve-2022-30190 follina office rce analysis [attached with customized word template POC]](/img/69/8f0381e99655009159c5119c7b896f.png)
Cve-2022-30190 follina office rce analysis [attached with customized word template POC]

国产框架MindSpore联合山水自然保护中心,寻找、保护「中华水塔」中的宝藏生命

Is there anyone who doesn't know the three cores of concurrent programming?

05 | standard design (Part 2): how to standardize the different styles of commit information, which are difficult to read?
![The [MySQL] time field is set to the current time by default](/img/40/5f1d3448259ab703c4b5dc29713a99.png)
The [MySQL] time field is set to the current time by default
随机推荐
Is there anyone who doesn't know the three cores of concurrent programming?
[test] the content of the hottest test development learning route has been updated again to help pass the customs and open the test of large factories
简单快速的数网络(网络中的网络套娃)
全网最全的混合精度训练原理
Alibaba cloud server purchase, basic configuration, (xshell) remote connection and environment building
技术干货|什么是大模型?超大模型?Foundation Model?
大赛报名 | AI+科学计算重点赛事之一——中国开源科学软件创意大赛,角逐十万奖金!
Target tracking shooting? Target occlusion shooting? With 1.9 billion installed petal apps, what unique features attract users?
Super hard core! Can the family photo album on Huawei's smart screen be classified automatically and accurately?
Hit the point! The largest model training collection!
Cvpr2022 stereo matching of asymmetric resolution images
指南针开户安全的吗?
[microservices] Understanding microservices
Moher College - SQL injection vulnerability test (error reporting and blind note)
test
Common techniques of email attachment phishing
Reading graph augmentations to learn graph representations (lg2ar)
论文学习——降雨场次划分方法对降雨控制率的影响分析
Safe and cost-effective payment in Thailand
Great health industry annual must attend event, 2022 Shandong International Great Health Industry Expo