当前位置:网站首页>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 .
边栏推荐
- Test interview questions collection (I) | common required questions and procedures of software testing (with answers)
- @PostConstruct注解及用处示例
- QT使用MSVC编译器输出中文乱码问题
- Ubuntu18.04+Centos7配置redis主从【学习笔记】
- Fermat's theorem
- 测试面试题集锦(五)| 自动化测试与性能测试篇(附答案)
- Project compilation nosuch*** error problem
- Yapi vulnerability hanging horse program chongfu.sh processing
- mongo ssl 配置实战
- [untitled]
猜你喜欢

技术分享 | 使用postman发送请求

mongoDB复制集及分片集群

Optimization ideas from ordinary query commodities to highly concurrent query commodities

explain详解

Technology sharing | send requests using postman

Technology sharing | sending requests using curl

Technology sharing | interface testing value and system

Qgraphicsview promoted to qchartview

Prometheus monitoring Nacos

Technology sharing | common proxy tools for interface testing
随机推荐
Pku-2524-ubiquitous relations (parallel search template)
RayMarching realizes volume light rendering
网络——传输层(详细版)
[c language] - step by step to achieve minesweeping games
Dynamic planning -- multi-step stair climbing (advanced version of stair climbing)
C language memcpy library functions and the role of memmove
archery数据库审核平台部署
mongoDB快速入门
[hash table basics]
Technology sharing | common proxy tools for interface testing
MySQL常用命令
[dynamic planning -- the best period series for buying and selling stocks]
Hdu-1159-commonsubsequence (LCS longest common subsequence)
Small tips
HDU-5806-NanoApeLovesSequenceⅡ(尺取法)
Source code analysis of countdownlatch of AQS
搭建PHP7私有仓库
进程和线程的区别
技术分享 | 如何模拟真实使用场景?mock 技术来帮你
测试面试题集锦(一)| 软件测试常见必考问题与流程篇(附答案)