我有两个Web应用程序。在第二个应用程序中有一个HttpSession,第一个应用程序知道它的sessionid。当使用Spring RestTemplate调用请求时无法检索cookie
我正在通过将第一个应用程序的会话ID添加到标题中,使用RestTemplate向第二个应用程序发出请求。
当在第二个应用程序收到请求时,我试图从请求中读取它的所有cookie。但是,我只能看到JSESSIONID cookie,并且没有获取我之前设置的所有cookie。
假设我手动访问浏览器上的相同网址,我看到所有检索到的cookie。
请求在第一次申请提出:
String sessionId = "6iuvgwy5ceqzwlxh646qo0ms";//SessionId of second application
String url = "http://example.com/data/retrieve";
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.add("Cookie", "JSESSIONID=" + sessionId);
HttpEntity<String> requestEntity = new HttpEntity<String>(null, requestHeaders);
ResponseEntity<String> responseEntity = restTemplate.exchange(url,
HttpMethod.GET, requestEntity, String.class);
如果无法使用Spring RestTemplate完成,请建议我,如果有做的任何其他方式。
在你的代码中,我只能看到一个Cookie被设置(JSESSIONID)。其他人在哪里? –
Roman,在App2中,正如我所说的,我有一个会话(我在另一个选项卡中的同一个浏览器中使用App2,我登录它并在登录后从java创建cookie(令牌))。从App1开始,我访问App2的资源(http://example.com/data/retrieve)和来自App1的jsessionid,当请求到达App2时,由于我在头文件中检索了jsessionid会话,但不是我登录后创建的会话的所有cookie。 – Ramang