当前位置: 首页 > news >正文

管理系统网站模板下载网站建设的数据所有权

管理系统网站模板下载,网站建设的数据所有权,郑州制作网站哪家好,桂阳做网站的软件定制开发外包文章目录 一、简要概述二、封装过程1. 引入依赖2. 定义脚本执行类 三、单元测试四、其他资源 一、简要概述 在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具#xff0c;可以说是一款很强大的http命令行工具。它支持文件的上传和下载#xff0c;是综合传输工具可以说是一款很强大的http命令行工具。它支持文件的上传和下载是综合传输工具但按传统习惯称curl为下载工具。它被广泛应用在Unix、多种Linux发行版中并且有DOS和Win32、Win64下的移植版本。 借助JAVA的shell脚本执行方法我们可以在curl命令支持下封装出一个代码精简且功能丰富的HTTP调用工具类。 二、封装过程 1. 引入依赖 pom.xml dependencygroupIdorg.slf4j/groupIdartifactIdslf4j-simple/artifactIdversion2.0.16/version /dependency dependencygroupIdorg.apache.commons/groupIdartifactIdcommons-lang3/artifactIdversion3.5/version /dependency dependencygroupIdcommons-io/groupIdartifactIdcommons-io/artifactIdversion2.15.0/version /dependency dependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdversion1.18.12/versionscopeprovided/scope /dependency dependencygroupIdorg.junit.jupiter/groupIdartifactIdjunit-jupiter-engine/artifactIdversion5.5.2/version /dependency2. 定义脚本执行类 ShellExecutor.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List;import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.SystemUtils;import lombok.extern.slf4j.Slf4j;Slf4j public class ShellExecutor {/*** execute命令* * param command* throws IOException*/public static void exec(String command){try{log.info(✈✈✈✈✈ WILL EXECUTE COMMAND: {} ✈✈✈✈✈, command);String[] cmd SystemUtils.IS_OS_WINDOWS ? new String[] {cmd, /c, command} : new String[] {/bin/sh, -c, command};Runtime.getRuntime().exec(cmd);}catch (IOException e){log.error(e.getMessage(), e);}}/*** execute命令* * param command* return 执行结果* throws IOException*/public static String execute(String command){try{log.info(✈✈✈✈✈ WILL EXECUTE COMMAND: {} ✈✈✈✈✈, command);String[] cmd SystemUtils.IS_OS_WINDOWS ? new String[] {cmd, /c, command} : new String[] {/bin/sh, -c, command};ListString resultList new ArrayList();try (BufferedReader br new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec(cmd).getInputStream()))){String line;while ((line br.readLine()) ! null){resultList.add(line);}}return StringUtils.join(resultList, System.lineSeparator());}catch (IOException e){log.error(e.getMessage(), e);return ;}} }上面的代码中我们我们定义了2个方法 exec 适用于不带返回值或返回值为非String类型的接口调用。 execute带String类返回值适用于restful接口json数据返回值的接口调用。 三、单元测试 import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets;import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.Test;import lombok.extern.slf4j.Slf4j;Slf4j public class ShellExecutorTest {Testpublic void test001()throws IOException{String response ShellExecutor.execute(curl https://00fly.online/upload/data.json);log.info(response);}Testpublic void test002()throws IOException{ShellExecutor.exec(curl -X GET -H \Accept:image/jpeg\ -H \Content-Type:application/x-www-form-urlencoded\ \https://00fly.online/upload/2019/02/201902262129360274AKuFZcUfip.jpg\ --output cat.jpg);}Testpublic void test003()throws IOException{String response ShellExecutor.execute(curl https://00fly.online/upload/data.json);FileUtils.writeStringToFile(new File(test.json), response, StandardCharsets.UTF_8, false);}Testpublic void test004()throws IOException{ShellExecutor.exec(curl https://00fly.online/upload/data.json -o test.json);ShellExecutor.exec(curl https://00fly.online/upload/data.json --output test2.json);}Testpublic void test005()throws IOException{// 模仿浏览器、伪造refererString response ShellExecutor.execute(curl -A \Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.0)\ -e \blog.csdn.net\ \https://blog.csdn.net/community/home-api/v1/get-business-list?page1size20businessTypelatelynoMorefalseusernameqq_16127313\);log.info(response);}Testpublic void test006()throws IOException{// 伪造refererString response ShellExecutor.execute(curl -e \blog.csdn.net\ \https://blog.csdn.net/community/home-api/v1/get-business-list?page1size20businessTypelatelynoMorefalseusernameqq_16127313\);log.info(response);} } 四、其他资源 更多CURL命令高级用法请参考curl文档 另外在线接口文档knife4j、httpbin等已经集成了等价curl命令各位可以拷贝测试自行探索。 注意如果需要将包含此工具的工程打包成docker镜像一定要在镜像构建文件Dockerfile中安装curl #安装curl RUN sed -i s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g /etc/apk/repositories apk update apk add curl有任何问题和建议都可以向我提问讨论,大家一起进步谢谢! -over-
http://www.dnsts.com.cn/news/190426.html

相关文章:

  • 郑州建设企业网站网站建设制作设计开发
  • 网站模版怎么做网站建站wordpress
  • 现在做网站还赚钱吗河北建设机械协会网站
  • 做网站多钱宝尊电商代运营入口
  • 昆明网站建设首选互维网站友情链接的作用
  • 地方门户网站的特点百度指数查询官方网
  • 济南公众平台网站建设网站开发服务费入什么科目
  • 织梦网站地图怎么做做一个公司的门户网站多少钱
  • 中国建设交易信息网站广州网站改版方案
  • 1做网站推广盘锦市建设银行网站
  • 口碑好的企业网站开发景点网站建设
  • 筑梦做网站网站怎么做才可以做评价
  • 网站数据库网络错误怎么解决方案广东手机网站建设报价表
  • 网站建设业动态网站建设构造学习
  • 电子商务网站建设与管理pdf下载企业移动网站品牌
  • 做网站用到什么开发语言个人微信小程序免费制作
  • 成考做那个网站的题比较好专业搜索引擎seo合作
  • wordpress编辑首页网络优化推广
  • 1688货源网登录wordpress谷歌seo
  • 如何开发一个软件seo网站关键词优化哪家好
  • 招聘信息网站建设网站开发工作方案
  • 成都公租房官方网站win7电脑做网站服务器
  • 部门网站建设方案新品发布会视频
  • 做百度快照要先有网站吗3合1网站建设价格
  • 天津网站建设代理商本公司经营网站建设
  • 网站建设初步策划方案wordpress插件根目录
  • 导航网站 win8风格宽带技术网网站
  • 岳阳高端网站建设手机系统网站
  • 外贸网站建设多少钱长沙seo
  • php mysql 网站建设特价服务器