【python接口自动化-requests库】【二】requests库简单使用(入门)

一、post请求

前面讲了,我们get请求的时候,引入requests的包,然后直接使用get方法,那么post是不是一样的?

1.首先我们先引入requests

import requests

2. requests.post(),从提示的代码我们可以看到,需要传的参数,有请求的URL,data字典等;

3.那我们怎么写呢?看下面,post(接口地址,字段data),一般我们post一个接口的时候,内容比较多,我们单独维护一个字典

 代码实例:

#先定义一个字典data,post请求一个地址
import requests
data = {}
response = requests.post(url="https://xxxx.xxxx.com/api/odds/getpceurooddslist",data=data)
print response.text

->实际案列:

结果->

原文地址:https://www.cnblogs.com/totoro-cat/p/10001549.html