RestTemplate

  1.我用RestTemplate请求时 我把他注入到容器里  这样可以 什么用什么时候拿

  2.也可以new出来 不过我不喜欢 所以就没有用new的

下面我自己的方法   先注入到容器 在 xxx-service.xml 里加上

<bean id="restTemplate" class="org.springframework.web.client.RestTemplate" ></bean>

然后用的时候

  @Autowired
private RestTemplate restTemplate;

get

@Override
public String seleteAllSeasonMatch(){
String url = xxx+"Season?seasontype=2";
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
httpHeaders.add("xxx",DATAVOLLEY_KEY);
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<MultiValueMap>( httpHeaders);
ResponseEntity<String> responseEntity =restTemplate.exchange(url,HttpMethod.GET,requestEntity,String.class);
String result = responseEntity.getBody();
System.out.println(result);;
return "";
}

post

     HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.add("xxx", "1.0");
//body
MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
requestBody.add("xxx", "1");
//HttpEntity
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<MultiValueMap>(requestBody, requestHeaders);
//post
ResponseEntity<String> responseEntity = restTemplate.postForEntity("http://xxx", requestEntity, String.class);
System.out.println(responseEntity.getBody());

Spring RestTemplate get post 请求 携带 headers的更多相关文章

  1. Spring RestTemplate 之get请求

    一,简介:Spring RestTemplate 是 Spring 提供的用于访问 Rest 服务的客户端,RestTemplate 提供了多种便捷访问远程Http服务的方法,能够大大提高客户端的编写 ...

  2. 通过 Spring RestTemplate 调用带请求体的 Delete 方法(Delete With Request Body)

    Spring 框架的RestTemplate 类定义了一些我们在通过 java 代码调用 Rest 服务时经常需要用到的方法,使得我们通过 java 调用 rest 服务时更加方便.简单.但是 Res ...

  3. spring restTemplate 进行http请求的工具类封装

    本文为博主原创,未经允许不得转载: 1.对常用调用的方法进行封装: import org.springframework.http.HttpHeaders; import com.alibaba.fa ...

  4. Spring RestTemplate 之post请求

    ●post请求:在RestTemplate中,POST请求可以通过如下三个方法来发起,但post提交方式又有两种 formData 和 payLoad,而且接口设计与传统的浏览器使用的提交方式又有差异 ...

  5. Spring RestTemplate 小结

    关于RestTemplate 首先,你可以把它理解为一个发起请求并接收响应的工具类(功能类似浏览器). 其次,它其实是一个壳,具体还是通过调用别的接口来实现(如jdk自带的连接,或者HttpClien ...

  6. Spring RestTemplate中几种常见的请求方式GET请求 POST请求 PUT请求 DELETE请求

    Spring RestTemplate中几种常见的请求方式 原文地址: https://blog.csdn.net/u012702547/article/details/77917939   版权声明 ...

  7. Spring RestTemplate: 比httpClient更优雅的Restful URL访问, java HttpPost with header

    { "Author": "tomcat and jerry", "url":"http://www.cnblogs.com/tom ...

  8. Spring RestTemplate介绍

    http://www.cnblogs.com/rollenholt/p/3894117.html RestTemplate 这篇文章打算介绍一下Spring的RestTemplate.我这边以前设计到 ...

  9. Spring RestTemplate详解

    Spring RestTemplate详解   1.什么是REST? REST(RepresentationalState Transfer)是Roy Fielding 提出的一个描述互联系统架构风格 ...

随机推荐

  1. kinect 深度图与彩色图对齐程序

    //#include "duiqi.hpp" #include "kinect.h" #include <iostream> #include &q ...

  2. nginx日志 logrotate配置

    nginx 日志 logrotate配置如下: /var/log/nginx/*.log { daily missingok rotate 20 compress delaycompress noti ...

  3. 图论.DP

    见题: 看一眼,就知道是个依赖性背包,于是乎就草草的打了树上DP,一交发现才20,仔细检查也没错呀,忍不住点了题解,只喵一眼看到了强联通缩点等的字样,又重新审了一遍题,发现这句话理解有偏差:软件i只有 ...

  4. mui-H5获取当前手机通讯录

    mui.plusReady(function() { // 扩展API加载完毕,现在可以正常调用扩展API plus.contacts.getAddressBook(plus.contacts.ADD ...

  5. SpringCloud-day03-服务注册与发现组件Eureka

    5.服务注册与发现组件Eureka 5.1Eureka简介: Eureka是Netflix开发的服务发现框架,本身是一个基于REST的服务,主要用于定位运行在AWS域中的中间层服务,以达到负载均衡和中 ...

  6. [Solution] 893. Groups of Special-Equivalent Strings

    Difficulty: Easy Problem You are given an array A of strings. Two strings S and T are special-equiva ...

  7. React中this.props的主要属性

    this.props主要包含:history属性.location属性.match属性 ①history属性又包含 ②location属性又包含 ③match属性又包含

  8. vue 配置了全局的http拦截器,单独某个组件不需要这个拦截器,如何设置

    之前写过关于全局配置http拦截器的随笔,现在有个需求,在微信支付时,生成二维码,页面显示一个遮罩层,二维码页面需要每两秒请求一次接口,若返回结果为已支付,则进行页面跳转,但因为全局http中load ...

  9. Synchronized的几种用法

    https://blog.csdn.net/luoweifu/article/details/46613015

  10. java 调用存储过程

    1.java 中调用pl/sql 中的存储过程 call 存储过程的名称(参数名称,参数名称)  在service 层中调用  存储过程  String  sql=" call  proc_ ...