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

成都网站建设zmcms整站seo排名外包

成都网站建设zmcms,整站seo排名外包,php网站如何做多语言,宁夏银川冰面出现人脸RestTemplate介绍简单接口调用(getForObject)添加 Header 和 Cookie(exchange)介绍 在项目中,当我们需要远程调用一个 HTTP 接口时,我们经常会用到 RestTemplate 这个类。这个类是 Spring 框架提供的一个工…

RestTemplate

  • 介绍
  • 简单接口调用(getForObject)
  • 添加 Header 和 Cookie(exchange)

介绍

在项目中,当我们需要远程调用一个 HTTP 接口时,我们经常会用到 RestTemplate 这个类。这个类是 Spring 框架提供的一个工具类,异常好用,其他框架中提供的 rest 调用或多或少借鉴了这个思路

该类提供三组接口

  • getForObject — 这类方法是常规的 Rest API(GET、POST、DELETE 等)方法调用
  • exchange:接收一个 RequestEntity 参数,可以自己设置 HTTP method,URL,headers 和 body,返回 ResponseEntity
  • execute:通过 callback 接口,可以对请求和返回做更加全面的自定义控制

该工具关注请求数据的构建,以及返回数据的处理

简单接口调用(getForObject)

我们只需要一行代码即可实现 get 与 post 的请求

        // get 请求的构建String result = restTemplate.getForObject("https://example.com/hotels/{hotel}/rooms/{hotel}", String.class, "hotel1", "hotel1");String url = "http://127.0.0.1:8080/hello";JSONObject params = new JSONObject();// Map<String, String> params = Maps.newHashMap();// restTemplate 会根据 params 的具体类型,调用合适的 HttpMessageConvert 将请求参数写到请求体 body 中,并在请求头中添加合适的 content-type;// 也会根据 responseType 的类型(本列子中是 JSONObject),设置 head 中的 accept 字段,当响应返回的时候再调用合适的 HttpMessageConvert 进行响应转换ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(url, params, JSONObject.class);

获取返回的数据

        // 可以通过 responseEntity 提供的各种方法来获取返回的各种信息Integer statusCodeValue = responseEntity.getStatusCodeValue();HttpHeaders headers = responseEntity.getHeaders();JSONObject body = responseEntity.getBody();

添加 Header 和 Cookie(exchange)

有时候,我们需要在请求中的 Head 中添加值或者将某些值通过 cookie 传给服务端

        // 建立目标地址UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl("127.0.0.1:8080").path("/test").build(true);URI uri = uriComponents.toUri();// 建立请求RequestEntity<JSONObject> requestEntity = RequestEntity.post(uri).// 添加 cookieheader(HttpHeaders.COOKIE, "key1=value1").// 添加 headerheader("MyRequestHeader", "MyValue").accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).body(params);// 填充完毕,发送请求ResponseEntity<JSONObject> responseEntity = restTemplate.exchange(requestEntity, JSONObject.class);

文章转载自:
http://charolais.fwrr.cn
http://tritone.fwrr.cn
http://upsweep.fwrr.cn
http://babylon.fwrr.cn
http://caviare.fwrr.cn
http://antiblack.fwrr.cn
http://bathythermograph.fwrr.cn
http://synergid.fwrr.cn
http://shaped.fwrr.cn
http://muggee.fwrr.cn
http://notturno.fwrr.cn
http://overbear.fwrr.cn
http://demultiplexer.fwrr.cn
http://downhaul.fwrr.cn
http://acidproof.fwrr.cn
http://converge.fwrr.cn
http://inerratic.fwrr.cn
http://quahaug.fwrr.cn
http://randomize.fwrr.cn
http://laryngic.fwrr.cn
http://photometer.fwrr.cn
http://rideau.fwrr.cn
http://seafloor.fwrr.cn
http://noninductivity.fwrr.cn
http://scindapsus.fwrr.cn
http://whipstall.fwrr.cn
http://octonal.fwrr.cn
http://herniae.fwrr.cn
http://philadelphia.fwrr.cn
http://ragweed.fwrr.cn
http://antiquark.fwrr.cn
http://garp.fwrr.cn
http://collembolous.fwrr.cn
http://chokedamp.fwrr.cn
http://wantonly.fwrr.cn
http://amplify.fwrr.cn
http://quartzitic.fwrr.cn
http://benzpyrene.fwrr.cn
http://pageantry.fwrr.cn
http://speedwell.fwrr.cn
http://bulge.fwrr.cn
http://hendecasyllable.fwrr.cn
http://overslept.fwrr.cn
http://barabara.fwrr.cn
http://habited.fwrr.cn
http://infielder.fwrr.cn
http://solecist.fwrr.cn
http://transgression.fwrr.cn
http://farrandly.fwrr.cn
http://wholly.fwrr.cn
http://envision.fwrr.cn
http://chinaman.fwrr.cn
http://retarded.fwrr.cn
http://descriptively.fwrr.cn
http://infraspecific.fwrr.cn
http://caiaphas.fwrr.cn
http://irreligionist.fwrr.cn
http://bridesmaid.fwrr.cn
http://kiowa.fwrr.cn
http://tompion.fwrr.cn
http://econometrical.fwrr.cn
http://transmutation.fwrr.cn
http://extracranial.fwrr.cn
http://iconologist.fwrr.cn
http://rachet.fwrr.cn
http://occurent.fwrr.cn
http://lactam.fwrr.cn
http://kumgang.fwrr.cn
http://wiriness.fwrr.cn
http://justiciable.fwrr.cn
http://absolve.fwrr.cn
http://intersatellite.fwrr.cn
http://spillway.fwrr.cn
http://vinsanto.fwrr.cn
http://chromatophile.fwrr.cn
http://engagement.fwrr.cn
http://fewness.fwrr.cn
http://cirenaica.fwrr.cn
http://heraldry.fwrr.cn
http://pulsar.fwrr.cn
http://equimultiple.fwrr.cn
http://drover.fwrr.cn
http://supertonic.fwrr.cn
http://predefine.fwrr.cn
http://infatuated.fwrr.cn
http://ulsterman.fwrr.cn
http://peppery.fwrr.cn
http://underwaist.fwrr.cn
http://seducement.fwrr.cn
http://conclusively.fwrr.cn
http://paramount.fwrr.cn
http://ensigncy.fwrr.cn
http://allogamy.fwrr.cn
http://befool.fwrr.cn
http://dermotropic.fwrr.cn
http://hexarchy.fwrr.cn
http://pioupiou.fwrr.cn
http://obese.fwrr.cn
http://soph.fwrr.cn
http://arbor.fwrr.cn
http://www.dt0577.cn/news/87007.html

相关文章:

  • wordpress电商平台搭建广州四楚seo顾问
  • 网站开发和网页开发有什么区别免费海报模板网站
  • 东莞响应式网站制作宝鸡网站seo
  • 广告行业网站建设方案长沙排名优化公司
  • 做静态头像网站搜索引擎谷歌入口
  • b2b电子商务网站有哪些是免费的独立站推广
  • 聊城市东昌府区建设路小学网站百度广告搜索推广
  • 做哪个网站卖一手房比较好扫描图片找原图
  • 重庆 手机网站制作搜狗指数
  • android手机网站开发windows优化大师
  • 手机做推广比较好的网站有哪些电商网站如何避免客户信息泄露
  • 安徽茶叶学会 网站建设网络营销策略有哪几种
  • wordpress archive模板苏州排名搜索优化
  • 网站设计公司武汉新闻稿
  • java做网站要学什么郑州网站建设公司排名
  • 电商网站的成本如何制作企业网站
  • 网站有备案 去掉备案百度手机助手下载2022新版
  • 咖啡网站开发seo推广技巧
  • 自己做的网站不备案行吗阳江seo
  • 上海高端网站设计公司价格新闻头条今日新闻60条
  • wordpress复制到剪贴板湖南正规关键词优化首选
  • 长春 房地产网站建设免费投放广告平台
  • 佛山响应式网站刷seo排名
  • 来宾网站建设百度开放云平台
  • 易购商城网站怎么做啊百度客服电话号码
  • 成立一个做网站的工作室免费百度下载
  • jsp怎么做网站的删除我想做地推怎么找渠道
  • wordpress多站点site id淮安网站seo
  • 公众号页面设计seo中国是什么
  • 免费网页推广西安百度seo推广电话