在使用restTemplate.postForLocation()方法时,生产者(provider)返回的时候要设置请求头信息,不然返回的是null
    consumer:

    1. @RequestMapping("/postForLocation")
    2. public void postForLocation(){
    3. String url ="http://provider/postParam";
    4. Map<String, String> map = Collections.singletonMap("name", " memeda");
    5. URI location = restTemplate.postForLocation(url, map, Person.class);
    6. System.out.println(location);
    7. }

    provider:

    1. public URI postParam(@RequestBody Person person,HttpServletResponse response) throws Exception {
    2. URI uri = new URI("https://www.baidu.com/s?wd=" + person.getName());
    3. response.addHeader("Location", uri.toString());
    4. return uri;
    5. }