是否有适用于Android会话管理的特定库?我需要在普通的Android应用程序中管理我的会话,而不是在WebView
中。我可以从我的POST方法设置会话。但是当我发送另一个请求时,该会话就会丢失。有人可以帮我解决这个问题吗?
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("My url");
HttpResponse response = httpClient.execute(httppost);
List<Cookie> cookies = httpClient.getCookieStore().getCookies();
if (cookies.isEmpty()) {
System.out.println("None");
} else {
for (int i = 0; i < cookies.size(); i++) {
System.out.println("- " + cookies.get(i).toString());
}
}
当我尝试访问同一主机时会丢失会话:
HttpGet httpGet = new HttpGet("my url 2");
HttpResponse response = httpClient.execute(httpGet);
我获得了登录页面的响应内容。