Postman: Postman (HTTP testing tool) using the method detailed Raiders - be finishing

 

 

Postman has many features, this article only describes how the core of the hair GET, POST's.

And back-end simulation using the postman flask of Get / Post data exchange
1, Get interactive mode
1.1, first run the program Flask
python flask write the code, the program is being tested using a procedure Flask, Flask framework is a python-based web site.

Import the Flask the Flask from
from the Flask Import Request, jsonify
 
'' '
route method @ app.route calling app (inherited Flask) as a decorative function, the parameters when calling app.route contact function is decorated up. Three decorator effects include:
         the relative address '/', the GET method (the default), the display function index link
         relative address '/ index', the GET method (default), associated with the display function index up
         relative address '/ postjson' method POST, linked to the display function postJsonHandler.
(1), that is, when the relative address of the browser is '/' or '/ index', according to the GET method (browser address field acquisition parameters, the parameter is not present embodiment), the index function call.
(2), when the relative address of the browser '/ postjson', press the POST method (information acquisition parameters from the body), the function call postJsonHandler. The information stored in the request,
wherein the method get__json, separated data, and are expressed in JSON (Javascript Object Notation).
'' '
 
 
Create instance a Flask, giving variable App
App = Flask (name__ __)
 
@ app.route (' / ') = # Default methods [' the GET ']
@ app.route (' / index ') # default methods = [ 'GET'

    response = {
        'from':     'index',
        'message': 'morning'
    }
    return jsonify(response), 200
 
 
 
 
@app.route('/postjson', methods=['POST'])
def postJsonHandler():
    print(request.is_json)
    content = request.get_json()
    print(content)
    return 'JSONposted'
 
app.run(host='0.0.0.0', port=8090)
 
 
 
 
 
 
#利用postman模拟与后端flask的Get/Post数据交互
#1、Get模式交互
 
# _*_ coding=utf-8 _*_
from flask import Flask
from flask import request, jsonify
 
 
app = Flask(__name__)
 
 
# @app.route('/get', methods=['GET', 'POST'])
@app.route('/') = # Default Methods [ 'the GET']
DEF GET ():
    name = request.args.get('name', '')
    if name == 'niu':
        age = 27
    else:
        age = 'valid name'
    return jsonify(
        data={name: age},
        extra={
            'total': '120'
        }
    )
 
 
if __name__ == '__main__':
    app.debug = True
    app.run(host='0.0.0.0', port=8001)
 
 

 

1.2, run Postman
start Postman, according prompts: http: //0.0.0.0: 8090 / or localhost: 8090 / index   
after running flask tips, and sometimes prompt is 0.0.0.0, such as: * Running onhttp: //0.0 .0.0: 8090 / (Press CTRL + C to quit).

Where localhost is the local domain name that is 127.0.0.1.
Program domain name is 0.0.0.0, also said that the local domain name, but after running a local domain name usually 127.0.0.1. For insurance purposes, the local domain name to localhost as well.
8090 is the port number
/ index is a relative URL address, request method to GET, expressed GET method request information is located in the URL field, server response information.
After the Send button, the server response information, see the red box, match the information corresponding to the program.


 

2, post interactive mode - sending a post using the postman
start Postman,
the first step, enter: http: //0.0.0.0: 8001 / post
Note: Remember to add post! ! ! ! !
The second step, Body → raw → the JSON selected, contents of the input: { "name": "niu "}
third step, the Send button, return JSON posted, and are displayed at both ends, the virtual web server and the client.

 

 
----------------
Disclaimer: This article is the original article CSDN blogger "program ape a Virgo", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //yunyaniu.blog.csdn.net/article/details/103903134

Released 1605 original articles · won praise 6377 · Views 12,580,000 +

Guess you like

Origin blog.csdn.net/qq_41185868/article/details/104584710