当前位置:网站首页>Technology sharing | detailed explanation of actual combat interface test request methods get, post
Technology sharing | detailed explanation of actual combat interface test request methods get, post
2022-07-28 06:51:00 【Yehna rahmin】
1、 The request method is different
2、post Can be attached body, Can support form、json、xml、binary And various data formats
3、 From the perspective of Industry General specifications , If there is no data change to the database , For example, query operation , It is recommended to use GET request , Data writing and status are recommended with POST request
Demonstration environment construction
In order to avoid the interference of other factors , Use flask Write a simple one demo server.
1、 install flask
pip install flask
- Create a hello.py file
from flask import Flask, request
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
@app.route("/request", methods=['POST', 'GET'])
def hellp():
# Get request Parameters
query = request.args
# Get request form
post = request.form
# Print the obtained parameters and form
return f"query: {query}\n"\
f"post: {post}"
- Start the service
export FLASK_APP=hello.py
flask run
The following information indicates that the construction is successful
* Serving Flask app "hello.py"
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
cURL Command initiation GET、POST request
launch GET request ,a、b Parameters are put into URL Sent in , And keep it in get In file
curl 'http://127.0.0.1:5000/request?a=1&b=2' -v -s &>get
launch POST request ,a、b Parameter with form-data Format send , And keep it in post In file
curl 'http://127.0.0.1:5000/request?' -d "a=1&b=2" -v -s &>post
GET、POST Request comparison
Be careful :> On the right side of is the request content ,< On the right is the response content
GET Request process
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)
> GET /request?a=1&b=2 HTTP/1.1
> Host: 127.0.0.1:5000
> User-Agent: curl/7.64.1
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: text/html; charset=utf-8
< Content-Length: 80
< Server: Werkzeug/0.14.1 Python/3.7.5
< Date: Wed, 01 Apr 2020 07:35:42 GMT
<
{ [80 bytes data]
* Closing connection 0
query: ImmutableMultiDict([('a', '1'), ('b', '2')])
post: ImmutableMultiDict([])
POST Request process
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)
> POST /request?a=1&b=2 HTTP/1.1
> Host: 127.0.0.1:5000
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Length: 7
> Content-Type: application/x-www-form-urlencoded
>
} [7 bytes data]
* upload completely sent off: 7 out of 7 bytes
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: text/html; charset=utf-8
< Content-Length: 102
< Server: Werkzeug/0.14.1 Python/3.7.5
< Date: Wed, 01 Apr 2020 08:15:08 GMT
<
{ [102 bytes data]
* Closing connection 0
query: ImmutableMultiDict([('a', '1'), ('b', '2')])
post: ImmutableMultiDict([('c', '3'), ('d', '4')])
Compare the two files :

You can see clearly from the picture GET Requested method by GET,POST Requested method by POST, Besides ,GET The request did not Content-Type as well as Content-Length These two fields , And... In the request line URL with query Parameters are the formats allowed by both requests .
边栏推荐
- 软件测试的生命周期(流程)
- MySQL主从
- [C language] custom structure type
- Question brushing record - linked list
- Skimming records -- sequence traversal of binary tree
- KVM hot migration
- 单元测试框架Jest搭配TypeScript的安装与配置
- 技术分享 | 接口测试常用代理工具
- JS four operations are repackaged to solve the problem of precision loss
- Brief analysis of order transaction
猜你喜欢

Centos7 deploy MySQL database server

Technology sharing | interface testing value and system

Using C language to realize three piece chess games

Technology sharing | how to simulate real use scenarios? Mock technology to help you

MySQL主主

mysql索引优化

Which brand of air conduction earphones is good and highly praised

Graphic pipeline foundation (part outside)
![[C language] dynamic memory management](/img/bb/2ec65b38e85f53269dc03d885d70f4.png)
[C language] dynamic memory management

Mongo SSL configuration practice
随机推荐
JS逆向100题——第1题
Lancher deployment practice
Installation and configuration of unit test framework jest with typescript
PKU-2524-Ubiquitous Religions(并查集模板)
Mongodb replica set and partitioned cluster
KVM热迁移
SSAO by computer shader (III)
Water rendering example
Build php7 private warehouse
Implementation of simple address book in [c language]
@Postconstruct annotations and useful examples
mongoDB复制集及分片集群
Optimization ideas from ordinary query commodities to highly concurrent query commodities
测试面试题集锦(五)| 自动化测试与性能测试篇(附答案)
Regular execution of scratch
Hdu-1159-commonsubsequence (LCS longest common subsequence)
[C language] string library function introduction and simulation
MySQL master-slave
什么是线性表?
如何描述一个BUG以及BUG级别的定义、生命周期