当前位置:网站首页>Interface test framework practice (I) | requests and interface request construction
Interface test framework practice (I) | requests and interface request construction
2022-06-27 01:10:00 【51CTO】
 Interface test framework practice ( One ) | Requests Interface request construction _ The interface test](/img/59/11dd165e88e3677b5abeca5de5ffff.jpg)
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 .
边栏推荐
- Law of Large Numbers
- Processing of slice loss in ArcGIS mosaic dataset
- Kept to implement redis autofailover (redisha) 11
- 数据库面试题+sql语句解析
- 2022年地理信息系统与遥感专业就业前景与升学高校排名选择
- Flink practical problems (VII): no watermark (watermarks are only available eventtime is used)
- The [MySQL] time field is set to the current time by default
- Account management, database building and four engines + cases of MySQL
- 自定义MVC(导成jar包)+与三层架构的区别+反射+面试题
- 3 - wire SPI Screen Drive
猜你喜欢

Processing of slice loss in ArcGIS mosaic dataset

About Random Numbers

Other service registration and discovery

ML:机器学习工程化之团队十大角色背景、职责、产出物划分之详细攻略

XSS攻击笔记(上)
![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

Gaussian and Summary Stats

气液滑环与其他滑环的工作原理有什么区别

Bootstrapblazor + FreeSQL actual combat chart usage (2)

直播回顾 | 子芽&CCF TF:云原生场景下软件供应链风险治理技术浅谈
随机推荐
疫情期间居家办公的总结体会 |社区征文
Is it safe to open a securities account online? Is it reliable to speculate in stocks by mobile phone
Other service registration and discovery
Memcached foundation 6
memcached基础5
TopoLVM: 基于LVM的Kubernetes本地持久化方案,容量感知,动态创建PV,轻松使用本地磁盘
Beyond lithium battery -- the concept of battery in the future
memcached基础6
Kept to implement redis autofailover (redisha) 17
IIS 部署静态网站和 FTP 服务
One click acceleration of Sony camera SD card file copy operation, file operation batch processing tutorial
memcached基础4
Processing of slice loss in ArcGIS mosaic dataset
Custom jsp[if, foreach, data, select] tag
These 10 copywriting artifacts help you speed up the code. Are you still worried that you can't write a copywriting for US media?
memcached基础1
Solve the problem that stc8g1k08 program cannot run and port configuration
ESP32实验-自建web服务器配网02
Flink practical problems (VII): no watermark (watermarks are only available eventtime is used)
Find the minimum value in the rotation sort array ii[classical Abstract dichotomy + how to break the game left, middle and right are equal]