简体   繁体   English

春天restTemplate

[英]Spring restTemplate

I'm trying to use spring rest template to do a post request to login in. 我正在尝试使用spring rest模板进行发布请求以登录。

RestTemplate restTemplate = new RestTemplate();

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

LinkedMultiValueMap<String, Object> mvm = new LinkedMultiValueMap<String, Object>();
mvm.add("LoginForm_Login", "login");
mvm.add("LoginForm_Password", "password");

ResponseEntity<String> result = restTemplate.exchange(uriDWLogin, HttpMethod.POST, requestEntity, String.class);

all goes well, but when I try to send a second request, It generates an error saying : 一切顺利,但是当我尝试发送第二个请求时,它会生成一条错误消息:

Business Manager closes your session after 15 minutes 15分钟后,业务经理将关闭您的会话

And i need to know can i use the resttemplate to manage sessions. 我需要知道我可以使用resttemplate来管理会话。

RestTemplate never manages session, nor do any of the service because all of them are stateless. RestTemplate从不管理会话,也不提供任何服务,因为它们都是无状态的。 If you want to manage the state, what you can do is get the token first time and then pass that token each time to the next service call. 如果要管理状态,您可以做的是首先获取令牌,然后每次将该令牌传递给下一个服务调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM