给请求加上头信息

    Request request = new Request();

   HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.add("accept", "application/json");
requestHeaders.add("content-type", "application/json");
requestHeaders.add("content-length", "256");
requestHeaders.add("authorization", authorization);
requestHeaders.setContentType(MediaType.APPLICATION_JSON)
   HttpEntity<?> httpEntity = new HttpEntity<Object>(request, requestHeaders);
  

    ResponseEntity<Response> response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, Response.class);
     return response.getBody();

有些请求是键值对的形式,用request的方法或封装HttpEntity也传不进去参数,可以尝试用下面的方法:

MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("shortcut", shortcut);
map.add("_api_key", apikey);
DefaultResponse response = restTemplate.postForObject(url, map, DefaultResponse.class);

从远程获取的list用resttemplate转成相应的对象

ObjectMapper mapper = new ObjectMapper();
DefaultResponse defaultResponse = rehabilitationProxy.getServiceDate();
List<Resource> resources =
(List<Resource>) defaultResponse.getData();
for (int i = 0; i < resources.size(); i++) {
Resource resource = mapper.convertValue(resources.get(i), Resource.class);
}

用RestTemplate碰到的问题的更多相关文章

  1. Spring Boot使用RestTemplate消费REST服务的几个问题记录

    我们可以通过Spring Boot快速开发REST接口,同时也可能需要在实现接口的过程中,通过Spring Boot调用内外部REST接口完成业务逻辑. 在Spring Boot中,调用REST Ap ...

  2. restTemplate.postForObject上传文件中文乱码(???.xls)

    一.问题描述 项目中, 使用restTemplate上传文件时, 文件名中文乱码, 一串问号, 源文件名为: 测试中文乱码哦哦哦.zip, 通过restTemplate.postForObject调用 ...

  3. RestTemplate最详解

    目录 1. RestTemplate简单使用 2. 一些其他设置 3. 简单总结 在项目中,当我们需要远程调用一个HTTP接口时,我们经常会用到RestTemplate这个类.这个类是Spring框架 ...

  4. RestTemplate 使用中的几个问题

    Spring Boot使用RestTemplate消费REST服务的几个问题记录 我们可以通过Spring Boot快速开发REST接口,同时也可能需要在实现接口的过程中,通过Spring Boot调 ...

  5. 通过`RestTemplate`上传文件(InputStreamResource详解)

    通过RestTemplate上传文件 1.上传文件File 碰到一个需求,在代码中通过HTTP方式做一个验证的请求,请求的参数包含了文件类型.想想其实很简单,直接使用定义好的MultiValueMap ...

  6. HttpClient的替代者 - RestTemplate

    需要的包 ,除了Spring的基础包外还用到json的包,这里的数据传输使用json格式 客户端和服务端都用到一下的包 <!-- Spring --> <dependency> ...

  7. RestTemplate发送请求并携带header信息

    1.使用restTemplate的postForObject方法 注:目前没有发现发送携带header信息的getForObject方法. HttpHeaders headers = new Http ...

  8. zk 起别名时候碰到的问题

    第一次搭建时候都是用的ip,没什么问题,看到别人都是用的别名,于是也想试试把ip改成别名.然而 其中碰到的问题 ,快一周了才解决,现在记录下: 1.改主机别名 一直以为 修改 /etc/hosts 里 ...

  9. 【Spring-web】RestTemplate源码学习——梳理内部实现过程

    2016-12-28 by 安静的下雪天  http://www.cnblogs.com/quiet-snowy-day/p/6228198.html  提示:使用手机浏览时请注意,图多费流量. 本篇 ...

随机推荐

  1. E: Sub-process /usr/bin/dpkg returned an error code (1) 解决方案

    转载自:http://www.cnblogs.com/eddy-he/archive/2012/06/20/2555918.html cd /var/lib/dpkg sudo mv info inf ...

  2. Winform自定义分页控件的实现

    实现效果 有点丑陋 但是功能是没问题的 测试过 实现思路 先创建一个用户控件 代码实现 public partial class PagerControl : UserControl { ; /// ...

  3. CALayer的分析

    转载地址:  http://my.oschina.net/u/2340880/blog/536048 iOS开发CoreAnimation解读之二——对CALayer的分析 一.UIView中的CAL ...

  4. UVA 11461 - Square Numbers

    题目:统计区间中的平方数个数. 分析: ... #include <stdio.h> #include <string.h> ]; int main() { int i, a, ...

  5. ruby学习总结05

    1.数值类(Numeric) 有理数:Rational(分子,分母) 复数:Complex(实数,虚数) 随机数:Rnadom   rand()  返回比1小的浮点数,rand(种子数)  返回0到该 ...

  6. 事务mysql

    一.事务的概念 事务指逻辑上的一组操作,组成这组操作的各个单元,要不全部成功,要不全部不成功. 例如:A——B转帐,对应于如下两条sql语句  update from account set mone ...

  7. which、whereis、locate、find 命令用法

    which.whereis.locate.find 命令用法   大部分转自http://312788172.iteye.com/blog/730280,有修改 我们经常在linux要查找某个文件,但 ...

  8. Know How To Use ID_NULL Function To Search An Object In Oracle Forms

    ID_NULL built in function is used to determine that an object type variable is null or not null in O ...

  9. json和jsonp的传输方式

    jsonp传输会解决跨域的问题 $.ajax({ async: false, /* url: "http://127.0.0.1:8080/2015020601/background/mea ...

  10. [HDOJ3911]Black And White(线段树,区间合并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3911 题意:一个01串,两种操作: 0 a b:查询[a,b]内连续1的最长长度. 1 a b:翻转[ ...