当前位置:网站首页>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 .
边栏推荐
- Sword finger offer 10- ii Frog jumping on steps
- Is there anyone who doesn't know the three cores of concurrent programming?
- JS library for number formatting
- Concepts de base de données Oracle
- 全網最全的混合精度訓練原理
- 消息队列简介
- 新型冠状病毒变异Delta毒株的模拟(MindSPONGE应用)
- 大健康行业年度必参盛会,2022山东国际大健康产业博览会
- From bitmap to bloom filter, C # implementation
- When transformer encounters partial differential equation solution
猜你喜欢

Target tracking shooting? Target occlusion shooting? With 1.9 billion installed petal apps, what unique features attract users?

com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string. at [Source:x

Introduction to message queuing

Using physical information neural network to solve hydrodynamics equations

When transformer encounters partial differential equation solution

滑环安装有哪些技巧和方法

为什么EDR需要深度防御来打击勒索软件?

Can't write to avoid killing and can easily go online CS through defender

Deep learning method for solving mean field game theory problems

05 | 规范设计(下):commit 信息风格迥异、难以阅读,如何规范?
随机推荐
新型冠状病毒变异Delta毒株的模拟(MindSPONGE应用)
Oracle 數據庫基本知識概念
气液滑环与其他滑环的工作原理有什么区别
目前哪个证券公司炒股开户是最好最安全的?
find_ Detailed use guide of CIRC
My advanced learning notes of C language ----- keywords
基于SSMP的宠物医院管理系统
CPU exception handling
互联网行业,常见含金量高的证书,看看你有几个?
An article takes you to learn container escape
冲刺强基计划数学物理专题二
Deep learning method for solving mean field game theory problems
MATLAB data type - character type
指南针开户安全的吗?
1+1<2 ?! HESIC论文解读
Using physical information neural network to solve hydrodynamics equations
串口调试工具 mobaxterm 下载
Network in network (dolls)
[vscode] setting sync, a plug-in for synchronizing extensions and settings
How to open an account on the mobile phone? Is it safe to open an account online and speculate in stocks