【python的requests库】
1、本地下载requests库
pip3 install requests
2.在pycharm中导入requests库



3、写代码
# -*- coding: utf-8 -*-
# @Time : 2020/8/17 6:05 下午
# @Author : yuxiaoxue
# @File : InterfaceAutomation.py
import requests
#最基本的get请求
get_test = requests.get('http://xiaobei-beta-c.beiins.com/myFamilyList')
#获取get请求的返回状态
print(get_test.status_code)
#带参数的get请求
httpbin_get = requests.get("http://xiaobei-beta-c.beiins.com/myFamilyList",params = {'wd':'python'})
#打印请求的url
print(httpbin_get.url)
#打印解码后的返回数据
print('httpbin_get:',httpbin_get.text)
#带参数的get请求
httpbin_get = requests.get("http://xiaobei-beta-c.beiins.com/myFamilyList",params = {'wd':'python'})
print(httpbin_get.url)
#打印解码后的返回数据
print('httpbin_get:',httpbin_get.text)
#带参数的post请求
httpbin_post = requests.post('http://www.itwhy.org/wp-comments-post.php',data={"comment":"测试post"})
print(httpbin_post.url)
print('httpbin_post:',httpbin_post.text)
post请求发送方式
url = 'http://httpbin.org/post'
#以form的形式发送post请求
d = {'key1': 'value1', 'key2': 'value2'}
r = requests.post(url,data=d)
print(r.text)
#以json的形式发送post请求
s =json.dumps(d)
r1 = requests.post(url, data=s)
print(r1.text)
#multipart形式发送post请求
files = {'file':open('yuxue.txt')}
r = requests.post(url,files = files)
print(r.text)

浙公网安备 33010602011771号