我需要使用Spring RestTemplate从服务器获取cookie。你们知道我怎么能这样做吗?
感谢您的帮助!
答案 0 :(得分:13)
final String url = "http://codeflex.co:8080/rest/Management/login";
RestTemplate template = new RestTemplate();
Credentials cred = new Credentials();
cred.setUserName("admin@codeflex.co");
cred.setPassword("godmode");
HttpEntity<Credentials> request = new HttpEntity<>(cred);
HttpEntity<String> response = template.exchange(url, HttpMethod.POST, request, String.class);
HttpHeaders headers = response.getHeaders();
String set_cookie = headers.getFirst(HttpHeaders.SET_COOKIE);
来自the example 的代码
答案 1 :(得分:-1)
Dictionary<string, string> childParent;
来自http://springinpractice.com/2012/04/08/sending-cookies-with-resttemplate