常见的requests的应用--GET/POST/PUT/DELETE/OPTION/HEAD

1. 下面四个都可以用于发送网页请求
# import urllib
# import urllib2
# import urllib3
# import http
import requests

2..使用requests发送get/post/put/delete等请求
  GTT参数
  URL?参数1=内容1&参数2=内容2...

  注意:参数部分不能出现空格或者特殊字符

3.例如:

response = requests.get("http://api.map.baidu.com/telematics/v3/weather?location=郑州市&output=json&ak=TueGDhCvwI6fOrQnLM0qmXxY9N0OkOiQ&callback=?")
print(response.content)
# response = requests.post()
# response = requests.put()
# response = requests.delete()

response = requests.get("https://www.baidu.com/s?wd=python")
print(response.content)
response = requests.get("https://www.baidu.com/s", params={"wd": "python"})
print(response.content)
4. 服务器向客户端返回的数据格式有哪些?
JSON/XML


5.,post的参数
 参数1:url
 参数2:data,类似于params
 参数3:json

 参数4:**kwargs

6.post例子

response = requests.post("http://dig.chouti.com/login",
                         data={
                             "phone": "8615896901897",
                             "password": "qweqweqwe1",
                             "oneMonth": "1"},
                         headers={
                             "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0"})
# print(response.content)
print(response.text)
f = open("chouti.html", "wb")
f.write(response.content)
f.close()

7.完整代码:

# -*- coding:utf-8 -*-

# 下面四个都可以用于发送网页请求
# import urllib
# import urllib2
# import urllib3
# import http
import requests

# 1.使用requests发送get/post/put/delete等请求
# GTT参数
# URL?参数1=内容1&参数2=内容2...
# 注意:参数部分不能出现空格或者特殊字符
response = requests.get("http://api.map.baidu.com/telematics/v3/weather?location=郑州市&output=json&ak=TueGDhCvwI6fOrQnLM0qmXxY9N0OkOiQ&callback=?")
print(response.content)
# response = requests.post()
# response = requests.put()
# response = requests.delete()


# 服务器向客户端返回的数据格式有哪些?
# JSON/XML

response = requests.get("https://www.baidu.com/s?wd=python")
print(response.content)


response = requests.get("https://www.baidu.com/s", params={"wd": "python"})
print(response.content)

# 参数1:url
# 参数2:data,类似于params
# 参数3:json
# 参数4:**kwargs
response = requests.post("http://dig.chouti.com/login",
                         data={
                             "phone": "8615896901897",
                             "password": "qweqweqwe1",
                             "oneMonth": "1"},
                         headers={
                             "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0"})
# print(response.content)
print(response.text)
f = open("chouti.html", "wb")
f.write(response.content)
f.close()

8.运行结果


-- 开始初始化数据 ; SET IDENTITY_INSERT sys_api ON; INSERT INTO sys_api (id, handle, title, path, type, "action", created_at, updated_at, deleted_at, create_by, update_by)VALUES (5, 'go-admin/app/admin/apis.SysLoginLog.Get-fm', '登录日志通过id获取', '/api/v1/sys-login-log/:id', 'BUS', 'GET', '2021-05-13 19:59:00.728', '2021-06-17 11:37:12.331', NULL, 0, 0), (6, 'go-admin/app/admin/apis.SysOperaLog.GetPage-fm', '操作日志列表', '/api/v1/sys-opera-log', 'BUS', 'GET', '2021-05-13 19:59:00.778', '2021-06-17 11:48:40.732', NULL, 0, 0), (7, 'go-admin/app/admin/apis.SysOperaLog.Get-fm', '操作日志通过id获取', '/api/v1/sys-opera-log/:id', 'BUS', 'GET', '2021-05-13 19:59:00.821', '2021-06-16 21:49:48.598', NULL, 0, 0), (8, 'go-admin/common/actions.IndexAction.func1', '分类列表', '/api/v1/syscategory', 'BUS', 'GET', '2021-05-13 19:59:00.870', '2021-06-13 20:53:47.883', NULL, 0, 0), (9, 'go-admin/common/actions.ViewAction.func1', '分类通过id获取', '/api/v1/syscategory/:id', 'BUS', 'GET', '2021-05-13 19:59:00.945', '2021-06-13 20:53:47.926', NULL, 0, 0), (10, 'go-admin/common/actions.IndexAction.func1', '内容列表', '/api/v1/syscontent', 'BUS', 'GET', '2021-05-13 19:59:01.005', '2021-06-13 20:53:47.966', NULL, 0, 0), (11, 'go-admin/common/actions.ViewAction.func1', '内容通过id获取', '/api/v1/syscontent/:id', 'BUS', 'GET', '2021-05-13 19:59:01.056', '2021-06-13 20:53:48.005', NULL, 0, 0), (15, 'go-admin/common/actions.IndexAction.func1', 'job列表', '/api/v1/sysjob', 'BUS', 'GET', '2021-05-13 19:59:01.248', '2021-06-13 20:53:48.169', NULL, 0, 0), (16, 'go-admin/common/actions.ViewAction.func1', 'job通过id获取', '/api/v1/sysjob/:id', 'BUS', 'GET', '2021-05-13 19:59:01.298', '2021-06-13 20:53:48.214', NULL, 0, 0), (21, 'go-admin/app/admin/apis.SysDictType.GetPage-fm', '字典类型列表', '/api/v1/dict/type', 'BUS', 'GET', '2021-05-13 19:59:01.525', '2021-06-17 11:48:40.732', NULL, 0, 0), (22, 'go-admin/app/admin/apis.SysDictType.GetAll-fm', '字典类型查询【代码生成】', '/api/v1/dict/type-option-select', 'SYS', 'GET', '2021-05-13 19:59:01.582', '2021-06-13 20:53:48.388', NULL, 0, 0), (23, 'go-admin/app/admin/apis.SysDictType.Get-fm', '字典类型通过id获取', '/api/v1/dict/type/:id', 'BUS', 'GET', '2021-05-13 19:59:01.632', '2021-06-17 11:48:40.732', NULL, 0, 0), (24, 'go-admin/app/admin/apis.SysDictData.GetPage-fm', '字典数据列表', '/api/v1/dict/data', 'BUS', 'GET', '2021-05-13 19:59:01.684', '2021-06-17 11:48:40.732', NULL, 0, 0), (25, 'go-admin/app/admin/apis.SysDictData.Get-fm', '字典数据通过code获取', '/api/v1/dict/data/:dictCode', 'BUS', 'GET', '2021-05-13 19:59:01.732', '2021-06-17 11:48:40.732', NULL, 0, 0), (26, 'go-admin/app/admin/apis.SysDictData.GetSysDictDataAll-fm', '数据字典根据key获取', '/api/v1/dict-data/option-select', 'SYS', 'GET', '2021-05-13 19:59:01.832', '2021-06-17 11:48:40.732', NULL, 0, 0), (27, 'go-admin/app/admin/apis.SysDept.GetPage-fm', '部门列表', '/api/v1/dept', 'BUS', 'GET', '2021-05-13 19:59:01.940', '2021-06-17 11:48:40.732', NULL, 0, 0), (28, 'go-admin/app/admin/apis.SysDept.Get-fm', '部门通过id获取', '/api/v1/dept/:id', 'BUS', 'GET', '2021-05-13 19:59:02.009', '2021-06-17 11:48:40.732', NULL, 0, 0), (29, 'go-admin/app/admin/apis.SysDept.Get2Tree-fm', '查询部门下拉树【角色权限-自定权限】', '/api/v1/deptTree', 'SYS', 'GET', '2021-05-13 19:59:02.050', '2021-06-17 11:48:40.732', NULL, 0, 0), (30, 'go-admin/app/admin/apis/tools.(*Gen).GetDBTableList-fm', '数据库表列表', '/api/v1/db/tables/page', 'SYS', 'GET', '2021-05-13 19:59:02.098', '2021-06-13 20:53:48.730', NULL, 0, 0), (31, 'go-admin/app/admin/apis/tools.(*Gen).GetDBColumnList-fm', '数据表列列表', '/api/v1/db/columns/page', 'SYS', 'GET', '2021-05-13 19:59:02.140', '2021-06-13 20:53:48.771', NULL, 0, 0), (32, 'go-admin/app/admin/apis/tools.Gen.GenCode-fm', '数据库表生成到项目', '/api/v1/gen/toproject/:tableId', 'SYS', 'GET', '2021-05-13 19:59:02.183', '2021-06-13 20:53:48.812', NULL, 0, 0), (33, 'go-admin/app/admin/apis/tools.Gen.GenMenuAndApi-fm', '数据库表生成到DB', '/api/v1/gen/todb/:tableId', 'SYS', 'GET', '2021-05-13 19:59:02.227', '2021-06-13 20:53:48.853', NULL, 0, 0), (34, 'go-admin/app/admin/apis/tools.(*SysTable).GetSysTablesTree-fm', '关系表数据【代码生成】', '/api/v1/gen/tabletree', 'SYS', 'GET', '2021-05-13 19:59:02.271', '2021-06-13 20:53:48.893', NULL, 0, 0), (35, 'go-admin/app/admin/apis/tools.Gen.Preview-fm', '生成预览通过id获取', '/api/v1/gen/preview/:tableId', 'SYS', 'GET', '2021-05-13 19:59:02.315', '2021-06-13 20:53:48.935', NULL, 0, 0), (36, 'go-admin/app/admin/apis/tools.Gen.GenApiToFile-fm', '生成api带文件', '/api/v1/gen/apitofile/:tableId', 'SYS', 'GET', '2021-05-13 19:59:02.357', '2021-06-13 20:53:48.977', NULL, 0, 0), (37, 'go-admin/app/admin/apis.System.GenerateCaptchaHandler-fm', '验证码获取', '/api/v1/getCaptcha', 'SYS', 'GET', '2021-05-13 19:59:02.405', '2021-06-13 20:53:49.020', NULL, 0, 0), (38, 'go-admin/app/admin/apis.SysUser.GetInfo-fm', '用户信息获取', '/api/v1/getinfo', 'SYS', 'GET', '2021-05-13 19:59:02.447', '2021-06-13 20:53:49.065', NULL, 0, 0), (39, 'go-admin/app/admin/apis.SysMenu.GetPage-fm', '菜单列表', '/api/v1/menu', 'BUS', 'GET', '2021-05-13 19:59:02.497', '2021-06-17 11:48:40.732', NULL, 0, 0), (40, 'go-admin/app/admin/apis.SysMenu.GetMenuTreeSelect-fm', '查询菜单下拉树结构【废弃】', '/api/v1/menuTreeselect', 'SYS', 'GET', '2021-05-13 19:59:02.542', '2021-06-03 22:37:21.857', NULL, 0, 0), (41, 'go-admin/app/admin/apis.SysMenu.Get-fm', '菜单通过id获取', '/api/v1/menu/:id', 'BUS', 'GET', '2021-05-13 19:59:02.584', '2021-06-17 11:48:40.732', NULL, 0, 0), (42, 'go-admin/app/admin/apis.SysMenu.GetMenuRole-fm', '角色菜单【顶部左侧菜单】', '/api/v1/menurole', 'SYS', 'GET', '2021-05-13 19:59:02.630', '2021-06-13 20:53:49.574', NULL, 0, 0), (43, 'go-admin/app/admin/apis.SysMenu.GetMenuIDS-fm', '获取角色对应的菜单id数组【废弃】', '/api/v1/menuids', 'SYS', 'GET', '2021-05-13 19:59:02.675', '2021-06-03 22:39:52.500', NULL, 0, 0), (44, 'go-admin/app/admin/apis.SysRole.GetPage-fm', '角色列表', '/api/v1/role', 'BUS', 'GET', '2021-05-13 19:59:02.720', '2021-06-17 11:48:40.732', NULL, 0, 0), (45, 'go-admin/app/admin/apis.SysMenu.GetMenuTreeSelect-fm', '菜单权限列表【角色配菜单使用】', '/api/v1/roleMenuTreeselect/:roleId', 'SYS', 'GET', '2021-05-13 19:59:02.762', '2021-06-17 11:48:40.732', NULL, 0, 0), (46, 'go-admin/app/admin/apis.SysDept.GetDeptTreeRoleSelect-fm', '角色部门结构树【自定义数据权限】', '/api/v1/roleDeptTreeselect/:roleId', 'SYS', 'GET', '2021-05-13 19:59:02.809', '2021-06-17 11:48:40.732', NULL, 0, 0), (47, 'go-admin/app/admin/apis.SysRole.Get-fm', '角色通过id获取', '/api/v1/role/:id', 'BUS', 'GET', '2021-05-13 19:59:02.850', '2021-06-17 11:48:40.732', NULL, 0, 0), (48, 'github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth.(*GinJWTMiddleware).RefreshHandler-fm', '刷新token', '/api/v1/refresh_token', 'SYS', 'GET', '2021-05-13 19:59:02.892', '2021-06-13 20:53:49.278', NULL, 0, 0), (53, 'go-admin/app/admin/apis.SysConfig.GetPage-fm', '参数列表', '/api/v1/config', 'BUS', 'GET', '2021-05-13 19:59:03.116', '2021-06-17 11:48:40.732', NULL, 0, 0), (54, 'go-admin/app/admin/apis.SysConfig.Get-fm', '参数通过id获取', '/api/v1/config/:id', 'BUS', 'GET', '2021-05-13 19:59:03.157', '2021-06-17 11:48:40.732', NULL, 0, 0), (55, 'go-admin/app/admin/apis.SysConfig.GetSysConfigByKEYForService-fm', '参数通过键名搜索【基础默认配置】', '/api/v1/configKey/:configKey', 'SYS', 'GET', '2021-05-13 19:59:03.198', '2021-06-13 20:53:49.745', NULL, 0, 0), (57, 'go-admin/app/jobs/apis.SysJob.RemoveJobForService-fm', 'job移除', '/api/v1/job/remove/:id', 'BUS', 'GET', '2021-05-13 19:59:03.295', '2021-06-13 20:53:49.786', NULL, 0, 0), (58, 'go-admin/app/jobs/apis.SysJob.StartJobForService-fm', 'job启动', '/api/v1/job/start/:id', 'BUS', 'GET', '2021-05-13 19:59:03.339', '2021-06-13 20:53:49.829', NULL, 0, 0), (59, 'go-admin/app/admin/apis.SysPost.GetPage-fm', '岗位列表', '/api/v1/post', 'BUS', 'GET', '2021-05-13 19:59:03.381', '2021-06-17 11:48:40.732', NULL, 0, 0), (60, 'go-admin/app/admin/apis.SysPost.Get-fm', '岗位通过id获取', '/api/v1/post/:id', 'BUS', 'GET', '2021-05-13 19:59:03.433', '2021-06-17 11:48:40.732', NULL, 0, 0), (62, 'go-admin/app/admin/apis.SysConfig.GetSysConfigBySysApp-fm', '系统前端参数', '/api/v1/app-config', 'SYS', 'GET', '2021-05-13 19:59:03.526', '2021-06-13 20:53:49.994', NULL, 0, 0), (63, 'go-admin/app/admin/apis.SysUser.GetProfile-fm', '*用户信息获取', '/api/v1/user/profile', 'SYS', 'GET', '2021-05-13 19:59:03.567', '2021-06-13 20:53:50.038', NULL, 0, 0), (66, 'github.com/go-admin-team/go-admin-core/sdk/pkg/ws.(*Manager).WsClient-fm', '链接ws【定时任务log】', '/ws/:id/:channel', 'BUS', 'GET', '2021-05-13 19:59:03.705', '2021-06-13 20:53:50.167', NULL, 0, 0), (67, 'github.com/go-admin-team/go-admin-core/sdk/pkg/ws.(*Manager).UnWsClient-fm', '退出ws【定时任务log】', '/wslogout/:id/:channel', 'BUS', 'GET', '2021-05-13 19:59:03.756', '2021-06-13 20:53:50.209', NULL, 0, 0), (68, 'go-admin/common/middleware/handler.Ping', '*用户基本信息', '/info', 'SYS', 'GET', '2021-05-13 19:59:03.800', '2021-06-13 20:53:50.251', NULL, 0, 0), (72, 'go-admin/common/actions.CreateAction.func1', '分类创建', '/api/v1/syscategory', 'BUS', 'POST', '2021-05-13 19:59:03.982', '2021-06-13 20:53:50.336', NULL, 0, 0), (73, 'go-admin/common/actions.CreateAction.func1', '内容创建', '/api/v1/syscontent', 'BUS', 'POST', '2021-05-13 19:59:04.027', '2021-06-13 20:53:50.375', NULL, 0, 0), (76, 'go-admin/common/actions.CreateAction.func1', 'job创建', '/api/v1/sysjob', 'BUS', 'POST', '2021-05-13 19:59:04.164', '2021-06-13 20:53:50.500', NULL, 0, 0), (80, 'go-admin/app/admin/apis.SysDictData.Insert-fm', '字典数据创建', '/api/v1/dict/data', 'BUS', 'POST', '2021-05-13 19:59:04.347', '2021-06-17 11:48:40.732', NULL, 0, 0), (81, 'go-admin/app/admin/apis.SysDictType.Insert-fm', '字典类型创建', '/api/v1/dict/type', 'BUS', 'POST', '2021-05-13 19:59:04.391', '2021-06-17 11:48:40.732', NULL, 0, 0), (82, 'go-admin/app/admin/apis.SysDept.Insert-fm', '部门创建', '/api/v1/dept', 'BUS', 'POST', '2021-05-13 19:59:04.435', '2021-06-17 11:48:40.732', NULL, 0, 0), (85, 'github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth.(*GinJWTMiddleware).LoginHandler-fm', '*登录', '/api/v1/login', 'SYS', 'POST', '2021-05-13 19:59:04.597', '2021-06-13 20:53:50.784', NULL, 0, 0), (86, 'go-admin/common/middleware/handler.LogOut', '*退出', '/api/v1/logout', 'SYS', 'POST', '2021-05-13 19:59:04.642', '2021-06-13 20:53:50.824', NULL, 0, 0), (87, 'go-admin/app/admin/apis.SysConfig.Insert-fm', '参数创建', '/api/v1/config', 'BUS', 'POST', '2021-05-13 19:59:04.685', '2021-06-17 11:48:40.732', NULL, 0, 0), (88, 'go-admin/app/admin/apis.SysMenu.Insert-fm', '菜单创建', '/api/v1/menu', 'BUS', 'POST', '2021-05-13 19:59:04.777', '2021-06-17 11:48:40.732', NULL, 0, 0), (89, 'go-admin/app/admin/apis.SysPost.Insert-fm', '岗位创建', '/api/v1/post', 'BUS', 'POST', '2021-05-13 19:59:04.886', '2021-06-17 11:48:40.732', NULL, 0, 0), (90, 'go-admin/app/admin/apis.SysRole.Insert-fm', '角色创建', '/api/v1/role', 'BUS', 'POST', '2021-05-13 19:59:04.975', '2021-06-17 11:48:40.732', NULL, 0, 0), (91, 'go-admin/app/admin/apis.SysUser.InsetAvatar-fm', '*用户头像编辑', '/api/v1/user/avatar', 'SYS', 'POST', '2021-05-13 19:59:05.058', '2021-06-13 20:53:51.079', NULL, 0, 0), (92, 'go-admin/app/admin/apis.SysApi.Update-fm', '接口编辑', '/api/v1/sys-api/:id', 'BUS', 'PUT', '2021-05-13 19:59:05.122', '2021-06-17 11:48:40.732', NULL, 0, 0), (95, 'go-admin/common/actions.UpdateAction.func1', '分类编辑', '/api/v1/syscategory/:id', 'BUS', 'PUT', '2021-05-13 19:59:05.255', '2021-06-13 20:53:51.247', NULL, 0, 0), (96, 'go-admin/common/actions.UpdateAction.func1', '内容编辑', '/api/v1/syscontent/:id', 'BUS', 'PUT', '2021-05-13 19:59:05.299', '2021-06-13 20:53:51.289', NULL, 0, 0), (97, 'go-admin/common/actions.UpdateAction.func1', 'job编辑', '/api/v1/sysjob', 'BUS', 'PUT', '2021-05-13 19:59:05.343', '2021-06-13 20:53:51.331', NULL, 0, 0), (101, 'go-admin/app/admin/apis.SysDictData.Update-fm', '字典数据编辑', '/api/v1/dict/data/:dictCode', 'BUS', 'PUT', '2021-05-13 19:59:05.519', '2021-06-17 11:48:40.732', NULL, 0, 0), (102, 'go-admin/app/admin/apis.SysDictType.Update-fm', '字典类型编辑', '/api/v1/dict/type/:id', 'BUS', 'PUT', '2021-05-13 19:59:05.569', '2021-06-17 11:48:40.732', NULL, 0, 0), (103, 'go-admin/app/admin/apis.SysDept.Update-fm', '部门编辑', '/api/v1/dept/:id', 'BUS', 'PUT', '2021-05-13 19:59:05.613', '2021-06-17 11:48:40.732', NULL, 0, 0), (104, 'go-admin/app/other/apis.SysFileDir.Update-fm', '文件夹编辑', '/api/v1/file-dir/:id', 'BUS', 'PUT', '2021-05-13 19:59:05.662', '2021-06-13 20:53:51.847', NULL, 0, 0), (105, 'go-admin/app/other/apis.SysFileInfo.Update-fm', '文件编辑', '/api/v1/file-info/:id', 'BUS', 'PUT', '2021-05-13 19:59:05.709', '2021-06-13 20:53:51.892', NULL, 0, 0), (106, 'go-admin/app/admin/apis.SysRole.Update-fm', '角色编辑', '/api/v1/role/:id', 'BUS', 'PUT', '2021-05-13 19:59:05.752', '2021-06-17 11:48:40.732', NULL, 0, 0), (107, 'go-admin/app/admin/apis.SysRole.Update2DataScope-fm', '角色数据权限修改', '/api/v1/roledatascope', 'BUS', 'PUT', '2021-05-13 19:59:05.803', '2021-06-17 11:48:40.732', NULL, 0, 0), (108, 'go-admin/app/admin/apis.SysConfig.Update-fm', '参数编辑', '/api/v1/config/:id', 'BUS', 'PUT', '2021-05-13 19:59:05.848', '2021-06-17 11:48:40.732', NULL, 0, 0), (109, 'go-admin/app/admin/apis.SysMenu.Update-fm', '编辑菜单', '/api/v1/menu/:id', 'BUS', 'PUT', '2021-05-13 19:59:05.891', '2021-06-17 11:48:40.732', NULL, 0, 0), (110, 'go-admin/app/admin/apis.SysPost.Update-fm', '岗位编辑', '/api/v1/post/:id', 'BUS', 'PUT', '2021-05-13 19:59:05.934', '2021-06-17 11:48:40.732', NULL, 0, 0), (111, 'go-admin/app/admin/apis.SysUser.UpdatePwd-fm', '*用户修改密码', '/api/v1/user/pwd', 'SYS', 'PUT', '2021-05-13 19:59:05.987', '2021-06-13 20:53:51.724', NULL, 0, 0), (112, 'go-admin/common/actions.DeleteAction.func1', '分类删除', '/api/v1/syscategory', 'BUS', 'DELETE', '2021-05-13 19:59:06.030', '2021-06-13 20:53:52.237', NULL, 0, 0), (113, 'go-admin/common/actions.DeleteAction.func1', '内容删除', '/api/v1/syscontent', 'BUS', 'DELETE', '2021-05-13 19:59:06.076', '2021-06-13 20:53:52.278', NULL, 0, 0), (114, 'go-admin/app/admin/apis.SysLoginLog.Delete-fm', '登录日志删除', '/api/v1/sys-login-log', 'BUS', 'DELETE', '2021-05-13 19:59:06.118', '2021-06-17 11:48:40.732', NULL, 0, 0), (115, 'go-admin/app/admin/apis.SysOperaLog.Delete-fm', '操作日志删除', '/api/v1/sys-opera-log', 'BUS', 'DELETE', '2021-05-13 19:59:06.162', '2021-06-17 11:48:40.732', NULL, 0, 0), (116, 'go-admin/common/actions.DeleteAction.func1', 'job删除', '/api/v1/sysjob', 'BUS', 'DELETE', '2021-05-13 19:59:06.206', '2021-06-13 20:53:52.323', NULL, 0, 0), (117, 'go-admin/app/other/apis.SysChinaAreaData.Delete-fm', '行政区删除', '/api/v1/sys-area-data', 'BUS', 'DELETE', '2021-05-13 19:59:06.249', '2021-06-13 20:53:52.061', NULL, 0, 0), (120, 'go-admin/app/admin/apis.SysDictData.Delete-fm', '字典数据删除', '/api/v1/dict/data', 'BUS', 'DELETE', '2021-05-13 19:59:06.387', '2021-06-17 11:48:40.732', NULL, 0, 0), (121, 'go-admin/app/admin/apis.SysDictType.Delete-fm', '字典类型删除', '/api/v1/dict/type', 'BUS', 'DELETE', '2021-05-13 19:59:06.432', '2021-06-17 11:48:40.732', NULL, 0, 0), (122, 'go-admin/app/admin/apis.SysDept.Delete-fm', '部门删除', '/api/v1/dept/:id', 'BUS', 'DELETE', '2021-05-13 19:59:06.475', '2021-06-17 11:48:40.732', NULL, 0, 0), (123, 'go-admin/app/other/apis.SysFileDir.Delete-fm', '文件夹删除', '/api/v1/file-dir/:id', 'BUS', 'DELETE', '2021-05-13 19:59:06.520', '2021-06-13 20:53:52.539', NULL, 0, 0), (124, 'go-admin/app/other/apis.SysFileInfo.Delete-fm', '文件删除', '/api/v1/file-info/:id', 'BUS', 'DELETE', '2021-05-13 19:59:06.566', '2021-06-13 20:53:52.580', NULL, 0, 0), (125, 'go-admin/app/admin/apis.SysConfig.Delete-fm', '参数删除', '/api/v1/config', 'BUS', 'DELETE', '2021-05-13 19:59:06.612', '2021-06-17 11:48:40.732', NULL, 0, 0), (126, 'go-admin/app/admin/apis.SysMenu.Delete-fm', '删除菜单', '/api/v1/menu', 'BUS', 'DELETE', '2021-05-13 19:59:06.654', '2021-06-17 11:48:40.732', NULL, 0, 0), (127, 'go-admin/app/admin/apis.SysPost.Delete-fm', '岗位删除', '/api/v1/post/:id', 'BUS', 'DELETE', '2021-05-13 19:59:06.702', '2021-06-17 11:48:40.732', NULL, 0, 0), (128, 'go-admin/app/admin/apis.SysRole.Delete-fm', '角色删除', '/api/v1/role', 'BUS', 'DELETE', '2021-05-13 19:59:06.746', '2021-06-17 11:48:40.732', NULL, 0, 0), (131, 'github.com/go-admin-team/go-admin-core/tools/transfer.Handler.func1', '系统指标', '/api/v1/metrics', 'SYS', 'GET', '2021-05-17 22:13:55.933', '2021-06-13 20:53:49.614', NULL, 0, 0), (132, 'go-admin/app/other/router.registerMonitorRouter.func1', '健康状态', '/api/v1/health', 'SYS', 'GET', '2021-05-17 22:13:56.285', '2021-06-13 20:53:49.951', NULL, 0, 0), (133, 'go-admin/app/admin/apis.HelloWorld', '项目默认接口', '/', 'SYS', 'GET', '2021-05-24 10:30:44.553', '2021-06-13 20:53:47.406', NULL, 0, 0), (134, 'go-admin/app/other/apis.ServerMonitor.ServerInfo-fm', '服务器基本状态', '/api/v1/server-monitor', 'SYS', 'GET', '2021-05-24 10:30:44.937', '2021-06-13 20:53:48.255', NULL, 0, 0), (135, 'go-admin/app/admin/apis.SysApi.GetPage-fm', '接口列表', '/api/v1/sys-api', 'BUS', 'GET', '2021-05-24 11:37:53.303', '2021-06-17 11:48:40.732', NULL, 0, 0), (136, 'go-admin/app/admin/apis.SysApi.Get-fm', '接口通过id获取', '/api/v1/sys-api/:id', 'BUS', 'GET', '2021-05-24 11:37:53.359', '2021-06-17 11:48:40.732', NULL, 0, 0), (137, 'go-admin/app/admin/apis.SysLoginLog.GetPage-fm', '登录日志列表', '/api/v1/sys-login-log', 'BUS', 'GET', '2021-05-24 11:47:30.397', '2021-06-17 11:48:40.732', NULL, 0, 0), (138, 'go-admin/app/other/apis.File.UploadFile-fm', '文件上传', '/api/v1/public/uploadFile', 'SYS', 'POST', '2021-05-25 19:16:18.493', '2021-06-13 20:53:50.866', NULL, 0, 0), (139, 'go-admin/app/admin/apis.SysConfig.Update2Set-fm', '参数信息修改【参数配置】', '/api/v1/set-config', 'BUS', 'PUT', '2021-05-27 09:45:14.853', '2021-06-17 11:48:40.732', NULL, 0, 0), (140, 'go-admin/app/admin/apis.SysConfig.Get2Set-fm', '参数获取全部【配置使用】', '/api/v1/set-config', 'BUS', 'GET', '2021-05-27 11:54:14.384', '2021-06-17 11:48:40.732', NULL, 0, 0), (141, 'go-admin/app/admin/apis.SysUser.GetPage-fm', '管理员列表', '/api/v1/sys-user', 'BUS', 'GET', '2021-06-13 19:24:57.111', '2021-06-17 20:31:14.318', NULL, 0, 0), (142, 'go-admin/app/admin/apis.SysUser.Get-fm', '管理员通过id获取', '/api/v1/sys-user/:id', 'BUS', 'GET', '2021-06-13 19:24:57.188', '2021-06-17 20:31:14.318', NULL, 0, 0), (143, 'go-admin/app/admin/apis/tools.(*SysTable).GetSysTablesInfo-fm', '', '/api/v1/sys/tables/info', '', 'GET', '2021-06-13 19:24:57.437', '2021-06-13 20:53:48.047', NULL, 0, 0), (144, 'go-admin/app/admin/apis/tools.(*SysTable).GetSysTables-fm', '', '/api/v1/sys/tables/info/:tableId', '', 'GET', '2021-06-13 19:24:57.510', '2021-06-13 20:53:48.088', NULL, 0, 0), (145, 'go-admin/app/admin/apis/tools.(*SysTable).GetSysTableList-fm', '', '/api/v1/sys/tables/page', '', 'GET', '2021-06-13 19:24:57.582', '2021-06-13 20:53:48.128', NULL, 0, 0), (146, 'github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1', '', '/static/*filepath', '', 'GET', '2021-06-13 19:24:59.641', '2021-06-13 20:53:50.081', NULL, 0, 0), (147, 'github.com/swaggo/gin-swagger.CustomWrapHandler.func1', '', '/swagger/*any', '', 'GET', '2021-06-13 19:24:59.713', '2021-06-13 20:53:50.123', NULL, 0, 0), (148, 'github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1', '', '/form-generator/*filepath', '', 'GET', '2021-06-13 19:24:59.914', '2021-06-13 20:53:50.295', NULL, 0, 0), (149, 'go-admin/app/admin/apis/tools.(*SysTable).InsertSysTable-fm', '', '/api/v1/sys/tables/info', '', 'POST', '2021-06-13 19:25:00.163', '2021-06-13 20:53:50.539', NULL, 0, 0), (150, 'go-admin/app/admin/apis.SysUser.Insert-fm', '管理员创建', '/api/v1/sys-user', 'BUS', 'POST', '2021-06-13 19:25:00.233', '2021-06-17 20:31:14.318', NULL, 0, 0), (151, 'go-admin/app/admin/apis.SysUser.Update-fm', '管理员编辑', '/api/v1/sys-user', 'BUS', 'PUT', '2021-06-13 19:25:00.986', '2021-06-17 20:31:14.318', NULL, 0, 0), (152, 'go-admin/app/admin/apis/tools.(*SysTable).UpdateSysTable-fm', '', '/api/v1/sys/tables/info', '', 'PUT', '2021-06-13 19:25:01.149', '2021-06-13 20:53:51.375', NULL, 0, 0), (153, 'go-admin/app/admin/apis.SysRole.Update2Status-fm', '', '/api/v1/role-status', '', 'PUT', '2021-06-13 19:25:01.446', '2021-06-13 20:53:51.636', NULL, 0, 0), (154, 'go-admin/app/admin/apis.SysUser.ResetPwd-fm', '', '/api/v1/user/pwd/reset', '', 'PUT', '2021-06-13 19:25:01.601', '2021-06-13 20:53:51.764', NULL, 0, 0), (155, 'go-admin/app/admin/apis.SysUser.UpdateStatus-fm', '', '/api/v1/user/status', '', 'PUT', '2021-06-13 19:25:01.671', '2021-06-13 20:53:51.806', NULL, 0, 0), (156, 'go-admin/app/admin/apis.SysUser.Delete-fm', '管理员删除', '/api/v1/sys-user', 'BUS', 'DELETE', '2021-06-13 19:25:02.043', '2021-06-17 20:31:14.318', NULL, 0, 0), (157, 'go-admin/app/admin/apis/tools.(*SysTable).DeleteSysTables-fm', '', '/api/v1/sys/tables/info/:tableId', '', 'DELETE', '2021-06-13 19:25:02.283', '2021-06-13 20:53:52.367', NULL, 0, 0), (158, 'github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1', '', '/static/*filepath', '', 'HEAD', '2021-06-13 19:25:02.734', '2021-06-13 20:53:52.791', NULL, 0, 0), (159, 'github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1', '', '/form-generator/*filepath', '', 'HEAD', '2021-06-13 19:25:02.808', '2021-06-13 20:53:52.838', NULL, 0, 0); SET IDENTITY_INSERT sys_api OFF; 生成相对应的mysql 建表语句和insert语句
07-09
<template> <el-container class="activity-container"> <!--导航栏--> <el-header class="activity-header"> <h1>徐州传统文化推广网后台管理系统</h1> <div class="head-user"> <span>欢迎,{{username}}</span> <el-button type="text" @click="loginOut" class="logout-btn"> <i class="el-icon-switch-button"></i> 退出 </el-button> </div> </el-header> <!--主体--> <el-container> <!--侧边栏--> <el-row class="tac"> <el-col :span="12"> <el-menu default-active="2" class="custom-sidebar" @open="handleOpen" @close="handleClose" unique-opened=true background-color="#f0eae0" > <el-submenu index="1"> <template slot="title"> <i class="el-icon-s-custom"></i> <span>用户信息管理</span> </template> <el-menu-item-group> <el-menu-item index="1-1" @click="$router.push('/findUser')">用户信息</el-menu-item> <el-menu-item index="1-2" @click="$router.push('')">管理员信息</el-menu-item> </el-menu-item-group> </el-submenu> <el-submenu index="2"> <template slot="title"> <i class="el-icon-s-management"></i> <span>文化资源信息管理</span> </template> <el-menu-item-group> <el-menu-item index="2-1" @click="$router.push('/findCulture')">文化资源信息管理</el-menu-item> <el-menu-item index="2-2" @click="$router.push('/findCultureTopic')">文化专题信息管理</el-menu-item> </el-menu-item-group> </el-submenu> <el-submenu index="3"> <template slot="title"> <i class="el-icon-s-management"></i> <span>文化活动信息管理</span> </template> <el-menu-item-group> <el-menu-item index="3-1" @click="$router.push('')">线上活动</el-menu-item> <el-menu-item index="3-2" @click="$router.push('')">线下活动</el-menu-item> </el-menu-item-group> </el-submenu> <el-submenu index="4"> <template slot="title"> <i class="el-icon-s-promotion"></i> <span>互动交流信息管理</span> </template> <el-menu-item-group> <el-menu-item index="4-1" @click="$router.push('')">问题答疑</el-menu-item> <el-menu-item index="4-2" @click="$router.push('')">数据量</el-menu-item> </el-menu-item-group> </el-submenu> </el-menu> </el-col> </el-row> <!--页面右侧--> <el-main class="activity-main"> <div class="activity-content"> <el-form :model="ruleForm" ref="ruleForm" label-width="100px" class="ruleForm"> <el-form-item label="" > <el-input type="hidden" v-model="ruleForm.activity_id"></el-input> </el-form-item> <el-form-item label="活动名称" > <el-input v-model="ruleForm.title" placeholder="请输入活动名称"></el-input> </el-form-item> <el-form-item label="活动形式" prop="type"> <el-select v-model="ruleForm.type" placeholder="请选择活动形式"> <el-option label="线上" value="线上"></el-option> <el-option label="线下" value="线下"></el-option> </el-select> </el-form-item> <el-form-item label="活动简介"> <el-input v-model="ruleForm.introduction" placeholder="请输入活动简介"></el-input> </el-form-item> <el-form-item label="活动详情" prop="details"> <el-input v-model="ruleForm.details" type="textarea" rows="4" placeholder="请输入活动详情(时间,流程等)" ></el-input> </el-form-item> <el-form-item label="活动开始时间" prop="start_time"> <el-date-picker v-model="ruleForm.start_time" type="datetime" placeholder="选择活动开始时间" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;" ></el-date-picker> </el-form-item> <el-form-item label="活动截止时间" prop="end_time"> <el-date-picker v-model="ruleForm.end_time" type="datetime" placeholder="选择活动截止时间" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;" ></el-date-picker> </el-form-item> <el-form-item label="活动地点" > <el-input v-model="ruleForm.location" placeholder="请输入活动地点"></el-input> </el-form-item> <el-form-item label="报名截止时间" prop="deadline"> <el-date-picker v-model="ruleForm.deadline" type="datetime" placeholder="选择报名截止时间" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;" ></el-date-picker> </el-form-item> <el-form-item label="最大参与人数" > <el-input v-model="ruleForm.max_people" placeholder="请输入活动最大参与人数"></el-input> </el-form-item> <el-form-item label="视频"> <!-- 视频上传组件 --> <el-upload style="margin-left:14%;margin-top:5%" class="avatar-uploader el-upload--text" :drag="true" action="http://localhost:8080/api/uploadVideo" multiple :headers="headers" :show-file-list="false" :on-success="handleVideoSuccess" :before-upload="beforeUploadVideo" :on-progress="uploadVideoProcess" > <i v-if="!ruleForm.video" class="el-icon-upload"></i> <div v-if="!ruleForm.video" class="el-upload__text">将文件拖到此处,或点击上传</div> <!-- 上传进度显示 --> <el-progress v-if="videoFlag" type="circle" :percentage="videoUploadPercent" style="margin-top:30px;" ></el-progress> <!-- 视频预览 --> <div v-if="ruleForm.video" class="video-preview"> <video :src="ruleForm.video" controls style="max-width: 400px; margin-top: 15px;" ></video> <el-button type="text" style="color: #f56c6c; margin-top: 10px;" @click="removeVideo" > <i class="el-icon-delete"></i> 移除视频 </el-button> </div> <div class="el-upload__tip" slot="tip">只能上传mp4/flv/avi文件,且不超过300M</div> </el-upload> <!--隐藏的输入框,用于存储视频路径 --> <el-input v-model="ruleForm.video" placeholder="视频路径" style="display: none;" ></el-input> </el-form-item> <el-form-item label="浏览量" > <el-input v-model="ruleForm.view_count"></el-input> </el-form-item> <el-form-item label="活动状态" prop="status"> <el-select v-model="ruleForm.status" placeholder="请选择活动状态"> <el-option label="未开始" value="未开始"></el-option> <el-option label="进行中" value="进行中"></el-option> <el-option label="已结束" value="已结束"></el-option> </el-select> </el-form-item> <el-form-item align="center"> <el-button type="primary" @click="addActivity()" class="btn">提交</el-button> <el-button @click="resetForm('ruleForm')" class="btn1">重置</el-button> </el-form-item> </el-form> </div> </el-main> </el-container> </el-container> </template> <script> export default { name: `addActivity`, data(){ return{ username: sessionStorage.getItem("username"), ruleForm:{ activity_id:'', title:'', type:'', introduction:'', details:'', start_time:'', end_time:'', location:'', deadline:'', max_people:'', video:'', view_count:'', status:'' }, videoForm: { videoId: '', videoUrl: '' }, videoFlag: false, Plus: true, videoUploadPercent: 0, headers: { 'Content-Type': 'multipart/form-data' // 关键:确保请求头正确[^1] } } }, methods:{ loginOut() { sessionStorage.removeItem("username"); this.$router.push("/"); }, pageChange(index){ let title = this.title; this.$http.get("http://localhost:8081/activity/findActivityMo?index="+index+"&title="+title).then(req=>{ this.index=req.index; this.title=req.data.title; }) }, addActivity:function(){ let title=this.ruleForm.title; let type=this.ruleForm.type; let introduction=this.ruleForm.introduction; let details=this.ruleForm.details; let start_time=this.ruleForm.start_time; let end_time=this.ruleForm.end_time; let location=this.ruleForm.location; let deadline=this.ruleForm.deadline; let max_people=this.ruleForm.max_people; let video=this.ruleForm.video; let view_count=this.ruleForm.view_count; let status=this.ruleForm.status; this.$http.get("http://localhost:8081/activity/insertActivity?title="+title+"&type="+type+ "&introduction="+introduction+"&details="+details+ "&start_time="+start_time+"&end_time="+end_time+ "&location="+location+ "&deadline="+deadline+"&max_people="+max_people+"&video="+video+ "&view_count="+view_count+ "&status="+status).then(req=>{ if(req.data==true){ this.$message.success('添加成功'); this.$router.push({ name: "findActivity"}); } }) .catch(()=>{ this.$message.error('添加失败,请重试'); }); }, resetForm(formName) { this.$refs[formName].resetFields(); }, handleOpen(key, keyPath) { console.log(key, keyPath); }, handleClose(key, keyPath) { console.log(key, keyPath); }, // 视频上传前执行 beforeUploadVideo (file) { console.log('文件实际 MIME 类型:', file.type); // 调试用,查看真实类型 const isLt300M = file.size / 1024 / 1024 < 300 const allowedTypes = ['video/mp4', 'video/ogg', 'video/flv', 'video/avi', 'video/wmv', 'video/rmvb']; if (!allowedTypes.includes(file.type)) { this.$message.error('请上传正确的视频格式(mp4/ogg/flv/avi/wmv/rmvb)'); return false; } if (!isLt300M) { this.$message.error('上传视频大小不能超过300MB哦!'); return false; } }, uploadVideoProcess (event, file) { this.Plus = false; this.videoFlag = true; this.videoUploadPercent = Math.round(file.percentage); if (this.videoUploadPercent >= 100) { setTimeout(() => { this.videoFlag = false; }, 1000); } }, // 视频上传成功是执行 handleVideoSuccess (res) { this.Plus = false; this.videoUploadPercent = 100; console.log(res); if (res.resCode === '200') { // 关键:给表单的 video 字段赋值(用于提交) this.ruleForm.video = res.VideoUrl; // 必须加这行! this.videoForm.videoId = res.newVideoName; this.videoForm.videoUrl = res.VideoUrl; this.$message.success('视频上传成功!'); } else { this.$message.error('视频上传失败,请重新上传!'); } } } } </script> <style scoped> /*导航栏样式*/ .activity-header { /*设置背景为线性渐变效果*/ background: linear-gradient(90deg, #cbb89f 0%, #f0eae0 50%, #cbb89f 100%); display: flex; justify-content: space-between; align-items: center; padding: 0 20px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4); } h1 { color: white; font-size: 25px; font-weight: bold; margin-left: 20px; } .head-user { color: white; font-size: 16px; font-weight: bold; } .logout-btn { color: white; margin-left: 24px; font-size: 16px; transition: all 0.3s; } .logout-btn:hover { color: #b09d86; transform: scale(1.15); } /*侧边栏样式*/ .custom-sidebar { width: 240px; height: 1200px; border-right: 1px solid #e0d8c8; box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05); } .el-submenu .el-menu { background-color: #f5f0e8 !important; border-left: 3px solid #cbb89f; } .el-menu-item { height: 50px; line-height: 50px; padding-left: 60px !important; } .el-menu-item:hover{ background-color: #d8d0c2 !important; padding-left: 60px !important; } .el-menu-item.is-active { background-color: #cbb89f !important; color: #1a2b3c !important; font-weight: 600; } /*主内容样式*/ .activity-main { display: flex; } .activity-content { background-color: white; border-radius: 15px; box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.5); padding: 20px; width: 100%; } .video-preview { display: flex; justify-content: center; align-items: center; padding: 5px 0; } .no-video { color: #999; font-size: 14px; } .video-preview video { border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); } </style>package com.neu.activity.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.util.HashMap; import java.util.Map; import java.util.UUID; @Controller("activityVideoUpload") @CrossOrigin(origins = "http://localhost:8080", maxAge = 3600) public class VideoUpload { // 后端固定存储路径,可根据实际需求调整 private static final String SAVE_PATH = "D:/video/videoUpload"; @PostMapping(value = "/api/uploadVideo") @ResponseBody public Map<String, String> savaVideotest(@RequestParam("file") MultipartFile file) throws IllegalStateException { Map<String, String> resultMap = new HashMap<>(); try { // 获取文件后缀,前端已做格式限定,此处辅助校验 String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1) .toLowerCase(); // 重构文件名称,避免重名 String pikId = UUID.randomUUID().toString().replaceAll("-", ""); String newVideoName = pikId + "." + fileExt; System.out.println("重构后的文件名:" + newVideoName); // 确保存储目录存在,不存在则创建 File saveDir = new File(SAVE_PATH); if (!saveDir.exists()) { boolean isCreated = saveDir.mkdirs(); System.out.println("存储目录创建结果:" + isCreated); } // 保存视频文件 File fileSave = new File(SAVE_PATH, newVideoName); file.transferTo(fileSave); // 构造返回结果 resultMap.put("newVideoName", newVideoName); resultMap.put("resCode", "200"); resultMap.put("VideoUrl", SAVE_PATH + "/" + newVideoName); return resultMap; } catch (Exception e) { e.printStackTrace(); resultMap.put("resCode", "400"); return resultMap; } } }上传视频失败怎么解决
最新发布
08-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值