request
来源:互联网 发布:ubuntu哪个版本最稳定 编辑:程序博客网 时间:2024/06/10 16:43
发送请求
发送请求,以post为例
1.param形式传参:
import requestsurl = 'http://www.wozuishuai.com'param= { "params1":"value1"}requests.post(url=url, params=param)
2.body形式传参:
url = 'http://www.wozuishuai.com'body = { "params1":"value1"}requests.post(url=url, json=body)
3.x-www-form-urlencoded传参格式:
import requestsurl = 'http://www.wozuishuai.com'data = { "params1":"value1"}requests.post(url=url, data=data)
4.multipart/form-data传参格式:
import requestsurl = 'http://www.wozuishuai.com'files = { "params1":"value1", "files": ("1.png", open("这里是路径","rb"),"image/png")}r = requests.post(url=url, files=files)
5.定制header
import requestsheaders={ 'Connection': 'keep-alive', 'Content-Type': 'multipart/form-data; '}url = 'http://www.wozuishuai.com'r = requests.get(url=url,headers=headers)
聪明的人已经看出来了,想传什么参数只要对应一下参数名就OK了。其实requests里面有介绍的:
:param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param data: (optional) Dictionary or list of tuples ``[(key, value)]`` (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. :param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload. ``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')`` or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers to add for the file.
阅读全文
0 0
- Request
- request
- Request
- request
- request
- request
- Request
- request
- request
- request
- request
- request
- request
- Request
- request
- request
- request
- request
- Struts中的验证框架
- caioj1064 DP
- Java中的一对一关联关系(一)
- Swing学习----------QQ登录界面制作(一)
- MyEclipse 环境配置总结
- request
- 网易2017春招[编程题]双核处理
- mybatis IncompleteElementException:Could not find result map java.lang.String
- 使用hibernate5.2.10编写hibernate helloworld
- 最长回文子串
- 快速排序(分而治之策略及C语言实现)
- 【bzoj3733】[Pa2013]Iloczyn
- Swing学习----------QQ登录界面制作(二)
- Spring Boot第二弹:Spring Boot热插拔