python3+requests:get、post请求(python get、post)
2023-09-11 14:14:47 时间
1.get请求
(1)没有请求参数类型
response = requests.get(url='')
print(response.text)
(2)有请求参数的类型(键值对形式表示参数)
response = requests.get(url='',params={'key1':'value1','key2':'value2'})
print(response.text)
(3)有请求头(键值对形式表示请求头)
response = requests.get(url='',headers={'key1':'value1'})
print(response.text)
2.post请求
(1)请求正文是application/x-www-form-urlencoded
res = requests.post(url='',data={'key1':'value1','key2':'value2'},headers={'Content-Type':'application/x-www-form-urlencoded'})
print (res.json)
print (res.text)
(2)请求正文是multipart/form-data
res = requests.post(url='',data={'key1':'value1','key2':'value2'},headers={'Content-Type':'multipart/form-data'})
print (res.json)
print (res.text)
(3)请求正文是raw
传入xml格式文本
res = requests.post(url='',data='<?xml ?>',headers={'Content-Type':'text/xml'})
print (res.json)
print (res.text)
传入json格式文本
res = requests.post(url='',data=json.dumps({'key1':'value1','key2':'value2'}),headers={'Content-Type':'application/json'})
print (res.json)
print (res.text)
或者
res = requests.post(url='',json={{'key1':'value1','key2':'value2'}},headers={'Content-Type':'application/json'})
print (res.json)
print (res.text)
(4)请求正文是binary
res = requests.post(url='',files={'file':open('test.xls','rb')},headers={'Content-Type':'binary'})
print (res.json)
print (res.text)
相关文章
- selenium-webdriver(python) (十四) -- webdriver原理
- Python自定义线程类简单示例
- 【Python】python对象与json相互转换
- python:ERROR: No matching distribution found for Pillow==9.1.0的处理(Python 3.6.8)
- Python的IDE:基于Eclipse/MyEclipse软件的PyDev插件配置python的开发环境(不同python项目加载不同版本的python)—从而实现Python编程图文教程之详细攻略
- Python语言学习:解决python版本升级问题集合(python2系列→Python3系列)导致错误的总结集合
- 〖Python接口自动化测试实战篇⑧〗- 小案例 - 使用python实现接口请求 [查询天行数据]
- 从零开始学python | 使用Python映射,过滤和缩减函数:所有您需要知道的
- 从零开始学python | 什么是Python JSON?
- 【华为云技术分享】python教程:猴子补丁
- python模块之sniffio
- Python编程:Python2 和 Python3的字符串字典取值和MD5比较
- Python:使用2to3将Python2转Python3
- 聊天没有表情包被嘲讽,用python爬取了十万张表情包
- python自动化测试学习-Python测试框架之unittest和pytest
- python 合并k个有序链表
- python基础===解决python3 UnicodeEncodeError: 'gbk' codec can't encode character 'xXX' in position XX(转载)
- python基础===python3 get和post请求(转载)
- python基础===zip在python3中的用法
- python selenium
- 设计模式python版(6)-单例模式
- python3(十四)Python 异常处理
- 【异常】前端ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- python对月饼数据进行可视化,看看哪家最划算
- 第13讲:Python列表对象中元素的删操作
- Python常用内置函数(python 3.x)