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

网站建设投诉去哪里投诉百度上搜索关键词如何在首页

网站建设投诉去哪里投诉,百度上搜索关键词如何在首页,做网站如何在百度快照上排名,企业信息型网站有哪些一、详解 1.1 介绍 现如今的 Web 项目#xff0c;由服务端向外发起网络请求的场景#xff0c;基本上随处可见#xff01; 传统情况下#xff0c;在服务端代码里访问 http 服务时#xff0c;一般会使用 JDK 的 HttpURLConnection 或者 Apache 的 HttpClient#xff0c;不…一、详解 1.1 介绍 现如今的 Web 项目由服务端向外发起网络请求的场景基本上随处可见 传统情况下在服务端代码里访问 http 服务时一般会使用 JDK 的 HttpURLConnection 或者 Apache 的 HttpClient不过这种方法使用起来太过繁琐而且 api 使用起来非常的复杂还得操心资源回收。 1.2 什么是 HttpUtils HttpUtils 是 Solon 提供的进行远程调用客户端HttpUtils 提供了很多远程调用的方法能够大大提高客户端的编写效率。 HttpUtils 接口实现了 HttpURLConnection 的适配默认以及 OkHttp 的适配。官网地址 solon-net-httputils 1.3 引入依赖 dependencygroupIdorg.noear/groupIdartifactIdsolon-net-httputils/artifactId /dependencyHttpUtils 不需要初始化即可直接使用。而且可以直接使用负载均衡的能力需要引入 solon-cloud 的插件提供底层支持。像这样 HttpUtils.http(user-service, /user/get?id1).get();二、接口使用 HttpUtils 最大的特色就是对各种网络请求方式做了包装能极大的简化开发人员的工作量下面我们以 GET、POST、PUT、DELETE、文件上传与下载为例分别介绍各个API的使用方式。 2.1 GET 请求 通过 HttpUtils 发送 HTTP GET 协议请求经常使用到的方法有两个 get() - StringgetAs(Type type) - T 支持泛型 在 Solon 环境下写一个单元测试用例首先创建一个 Api 接口然后编写单元测试进行服务测试。 不带参的get请求 Controller public class TestController {GetMapping(testGet)public Result testGet(){Result result new Result();result.setCode(200);result.setMsg(demo...);return result;} }Data public class Result {private String code;private String msg; }单元测试不带参的get请求 Test public void testGet(){//请求地址String url http://localhost:8080/testGet;//发起请求,直接返回对象Result result HttpUtils.http(url).getAs(Result.class);System.out.println(result.toString());带参的get请求(使用占位符号传参) Controller public class TestController {GetMapping(testGetByRestFul/{id}/{name})public Result testGetByRestFul(Path(id) String id, Path(name) String name){Result result new Result();result.setCode(200);result.setMsg(demo...);return result;} }单元测试带参的get请求顺带加了个 header 信息。 Test public void testGetByRestFul(){//请求地址String url http://localhost:8080/testGetByRestFul/001/张三;//发起请求,直接返回对象restful风格Result result HttpUtils.http(url).header(App-Id,1).getAs(Result.class);System.out.println(result.toString()); }2.2 POST 请求 其实 POST 请求方法和 GET 请求方法上大同小异HttpUtils 的 POST 请求也包含两个主要方法 post() - StringpostAs(Type type) - T支持泛型 模拟表单请求post方法测试 Controller public class TestController {PostMapping(testPostByForm)public Result testPostByForm(String userName, String userPwd){Result result new Result();result.setCode(200);result.setMsg(Demo...);return result;} }x-www-form-urlencoded post Test public void testPostByForm(){//请求地址String url http://localhost:8080/testPostByForm;//发起请求Result result HttpUtils.http(url).data(userName, 唐三藏).data(userPwd, 123456).postAs(Result.class);System.out.println(result.toString()); }form-data post顺带加上文件上传 Test public void testPostByForm(){//请求地址String url http://localhost:8080/testPostByForm;//发起请求Result result HttpUtils.http(url).data(userName, 唐三藏).data(userPwd, 123456).data(file, logo.jpg, new File(/data/logo.jpg)) .postAs(Result.class, true); //useMultipart trueSystem.out.println(result.toString()); }json-body post Test public void testPostByForm(){//请求地址String url http://localhost:8080/testPostByForm;//发起请求Result result HttpUtils.http(url).bodyOfJson({\userName\:\唐三藏\,\userPwd\:\123456\}).postAs(Result.class); System.out.println(result.toString()); }bean-body post Test public void testPostByForm(){//请求地址String url http://localhost:8080/testPostByForm;UserBean user new UserBean();user.setUserName(唐三藏);user.setUserPwd(123456)//发起请求Result result HttpUtils.http(url).bodyOfBean(user).postAs(Result.class); System.out.println(result.toString()); }2.3 PUT、PATCH、DELETE 请求 用法与 POST 完全相同。 2.4 高级用法 获取响应用完要关闭 try(HttpResponse resp HttpUtils.http(http://localhost:8080/hello).data(name,world).exec(POST)) {int code resp.code();String head resp.header(Demo-Header);String body resp.bodyAsString(); }配置序列化器。默认为 json改为 fury或者自己定义。 FuryBytesSerializer serializer new FuryBytesSerializer();Result body HttpUtils.http(http://localhost:8080/book).serializer(serializer).bodyOfBean(book).postAs(Result.class);
http://www.w-s-a.com/news/827254/

相关文章:

  • 做网站的技术体系投资者互动平台官网
  • 北京网站建设公司哪家实惠企查查在线查询入口
  • 毕业设计做网站怎么样非微信官方网页自己做的网站
  • 昆明网站多端小程序设计重庆市住房和城乡建设厅网站
  • 网站制作技术人员国际新闻最新10条
  • 做同城特价的网站wordpress后台能修改模板文件
  • 网站信息可以边建设边组织产品展示网站源码php
  • 电子商务网站规划从哪些方面入手途牛企业网站建设方案
  • 莱阳网站定制易语言可以做网站嘛
  • 购物网站开发意义上海中小企业服务中心官网
  • 网站备案证书如何打开江苏网站建设电话
  • 深圳网站建设乐云seo搜索引擎优化seo目的
  • 中山城市建设集团网站网站建设设计基础
  • 网站开发流程莆田wordpress点播收费
  • 网站未及时续费浙江台州做网站的公司有哪些
  • 二级域名做网站好不好河源建网站
  • 公司网站的作用意义维护建设管理天津平台网站建设费用
  • 建设部网站如何下载国标规范上海影视公司
  • 企业官方网站地址通了网站建设
  • 专题网站可以做什么怎么做网站滑动图片部分h5
  • 什么是网站建设外包html 门户网站
  • 资阳市建设局网站微信开发公司
  • wap建站程序源码可不可以异地建设网站
  • 优秀企业网站的特点网站标签名词
  • 建材网站建设案例淄博网站建设培训
  • 纯代码添加wordpress网站底部导航宝塔自助建站源码
  • 网站设计技术有哪些?青岛网站建设工作室
  • 网站怎样建设才叫人性化宣传
  • 济南网站制作方案做淘客网站备案
  • h5企业网站只做做php门户网站那个系统好