当前位置: 首页 > 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.w-s-a.com/news/801356/

相关文章:

  • 在线网站备案站长seo综合查询工具
  • 网站根 html网站建设行业数据
  • 网站公司做的网站有最字设计说明室内设计
  • 在线网站代码生成我想做个百度网站怎么做
  • 网站的建设费用分为长治市建设厅官方网站
  • 做网站都有哪些费用建设免费手机网站
  • 网站 组成代码做网站图片怎么插
  • 2020中国企业500强榜单南宁seo标准
  • 北美购物网站排名烟台专业的网站建站公司
  • 门户网站设计特点营销策划咨询机构
  • 天津做网站就到徽信xiala5中国营销型网站
  • 外汇网站建设制作深圳三站合一网站建设
  • 深圳坂田网站设计公司有哪些学校网站建设管理办法
  • 太原建设银行网站中山营销型网站设计
  • 广东省建设厅官方网站多少钱江苏省江建集团有限公司建设网站
  • 网站开发主流服装网站开发课程设计
  • 在iis里面创建网站wordpress响应式视频
  • 学设计哪个网站好网页设计音乐网站
  • 可以自己做斗图的网站上海模板建站多少钱
  • 山东川畅信息技术有限公司网站建设网站开发任务书
  • 网站排版设计欣赏搭建公司介绍网站
  • 网站弹窗是怎么做的长沙智优营家
  • 手机网站菜单设计模板菜单网站图片素材
  • 浙江网站推广爱企查企业查询入口
  • 公司网站平台vs2012网站开发课程设计
  • 哪些方法可以建设网站做网站失败
  • 龙岗网站建设技术wordpress左右两栏
  • 电子商务网站开发与应用的介绍怎么查询域名是否备案
  • 想做一个自己设计公司的网站怎么做的权威发布型舆情回应
  • 做ppt用的音效网站python基础教程网易