码迷,mamicode.com
首页 > 编程语言 > 详细

python简说(二十四)发送网络请求

时间:2018-12-24 14:31:51      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:params   .text   str   one   strong   test   .json   text   and   

一.get,post请求
import requests
url=‘http://127.0.0.1:8999/api/upload‘
# data = {‘username‘:‘testuser1‘,‘passwd‘:‘111111‘}
# r = requests.get(url,params=data) #发get请求
# r = requests.post(url,data=data) #发post请求
# print(r.text) #结果返回的就是字符串
# print(r.json()) #结果返回的就是字典,必须返回的是json,才能转成字典
二.入参是json
# data = {
# "session_id":"6ab8785039dcf50fb11c53acc1db7648",
# "name":"zhouyongbo%s"%random.randint(1,99),
# "phone":"111211345%02d"%random.randint(1,99),
# "grade":"天秤座"
# }
# #
# r = requests.post(url,json=data) #入参是json类型的
三.上传文件

四.下载文件

五.添加header

python简说(二十四)发送网络请求

标签:params   .text   str   one   strong   test   .json   text   and   

原文地址:https://www.cnblogs.com/wangtingting920416/p/10168279.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!