安卓会话管理
2022-09-01 20:26:18
是否有用于 Android 会话管理的特定库?我需要在普通的 Android 应用程序中管理我的会话,而不是在 .我可以从我的post方法设置会话。但是当我发送另一个请求时,该会话丢失了。有人可以帮我这件事吗?WebView
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);
我得到登录页面响应正文。