我有一个web-appl:Spring MVC 4,Spring Data,Spring Security。如何登录(电子邮件)当前用户登录gmail帐户。我尝试从HttpServletRequest
获取cookie,但它不存储此数据。
我试着像这样得到cookie:
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cookieManager);
//creates url for the given string
URL url = null;
try {
url = new URL("https://www.google.co.in/");
//open's a connection with the url specified and returns URLConnection object
URLConnection urlConnection = url.openConnection();
// get's the contents from this url specifies
urlConnection.getContent();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//returns the cookie store(bunch of cookies)
CookieStore cookieStore = cookieManager.getCookieStore();
//getting cookies which returns in the form of List of type HttpCookie
List<HttpCookie> listOfcookies = cookieStore.getCookies();
for(HttpCookie httpCookie: listOfcookies){
System.out.println("Cookie Name : "+httpCookie.getName()+" Cookie Value : "+httpCookie.getValue());
}