马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
python的接口哀求可以用requests库,这个先容就不多说了,网上说得很具体。
接下来直接记录下怎样使用(固然也不限于自动化的使用)
1.安装requests
requests也必要安装一下
2.requests哀求
1.常用的哀求方法
接口哀求通常有get/post/put/delete等范例,我们可以直接根据这种范例哀求调用方法,比方:
- requests.get(url='')
- requests.post(url='', data='')
复制代码 这里我本身写了个简朴的服务,用于测试接口哀求,如下图能正常哀求到接口数据。
固然另有其他方法:
上面是用到哪个范例的哀求调用哪个范例,固然也有同一的方法
- requests.request(method='',url='') # :param method: method for the new :class:`Request` object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
复制代码 在这个方法中传入method参数即可,要调用get接口,就传入‘GET’,要调用post接口,就传入‘POST’。
如上图所示,也能调用乐成。
这里我们也可以看一下get方法的具体调用
实在就是get方法里调用了request方法,全部哀求方法都是基于request方法的。
2.哀求参数
这里附上request方法中解释,内里表明确各个参数的寄义:
- """Constructs and sends a :class:`Request <Request>`.
- :param method: method for the new :class:`Request` object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
- :param url: URL for the new :class:`Request` object.
- :param params: (optional) Dictionary, list of tuples or bytes to send
- in the query string for the :class:`Request`.
- :param data: (optional) Dictionary, list of tuples,
复制代码 |