我试图使用RestTemplate和Jackson json转换器调用Restful JSON服务.现在,为了调用服务,我需要传递一个安全cookie.我可以通过使用URLConnection来实现这一点(参见下面的代码)
URL url= new URL("https://XXXXXXXX"); URLConnection yc = url.openConnection(); yc.setRequestProperty("SecurityCookie", ssocookie.getValue());
什么是RestTemplate中的并行?这是我用来使用RestTemplate调用Restful Service的代码片段:
RestTemplate rest = new RestTemplate(); InputBean input = new InputBean(); input.setResource("SampleResource"); HttpEntityentity = new HttpEntity (input); ResponseEntity response1 = rest.postForEntity( "https://XXXXXXXXX", entity, OutputBean.class);
在使用RestTemplate调用服务时,我无法弄清楚如何传递安全cookie.对此的任何帮助都会很棒.
我写了一篇博客文章,解释了如何使用请求标头执行此操作:
http://springinpractice.com/2012/04/08/sending-cookies-with-resttemplate/
这是代码:
HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.add("Cookie", "JSESSIONID=" + session.getValue()); HttpEntity requestEntity = new HttpEntity(null, requestHeaders); ResponseEntity rssResponse = restTemplate.exchange( "https://jira.example.com/sr/jira.issueviews:searchrequest-xml/18107/SearchRequest-18107.xml?tempMax=1000", HttpMethod.GET, requestEntity, Rss.class); Rss rss = rssResponse.getBody();