python+requests for get and post method interface testing

Introduction: Requests is an HTTP library written in Python, based on urllib and using the Apache2 Licensed open source protocol. It is more convenient than urllib, can save us a lot of work, and fully meet the HTTP testing needs. The philosophy of Requests is developed around the idiom of PEP 20, so it is more Pythoner than urllib.

1. Request method type

1. Get request: requests.get('url')
2. Post request: requests.post("url/post")
3. Put request: requests.put("url/put")
4. Delete request: requests. delete("url/delete")
5. Head request: requests.head("url/get")
6. Options request: requests.options("url/get"), etc.

Today we will explain how to perform interface testing of get and post methods.

Two, get request

First quote the requests library and json library, because we are using requests for interface testing.

python+requests for get and post method interface testing

Check the results

python+requests for get and post method interface testing

Three, post request

The difference between post request and get request is that the post request needs to pass the body parameter

python+requests for get and post method interface testing

This is how python implements get and post interface requests

You can also use tools for interface testing, such as the domestic interface testing tool apipost

Use apipost for get request

python+requests for get and post method interface testing

Make a post request

python+requests for get and post method interface testing

It can also generate interface documents in various formats such as: word format interface documents

python+requests for get and post method interface testing

Download URL of domestic interface tool apipost:https://www.apipost.cn

Guess you like

Origin blog.51cto.com/12246704/2550608