我已经努力了一个月,试图弄清如何通过Android登录我的大学CAS系统。我对HTTP和身份验证一窍不通,花了很多时间搜索术语,但现在基本上掌握了它们。
无论如何,我正在尝试登录CAS系统,我能够找到系统如何工作的图表,我已经发布在下面。
这段代码没有返回任何错误,但只获取了一个cookie,我认为我需要另一个COOKIE——CASTGC cookie......
无论如何,我正在尝试登录CAS系统,我能够找到系统如何工作的图表,我已经发布在下面。
我目前有以下代码:
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpGet httpGet = new HttpGet(LOGIN);
HttpResponse response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
Log.i(TAG, "Login form get: " + response.getStatusLine());
if (entity != null) {
entity.consumeContent();
}
Log.i(TAG, "Initial set of cookies: ");
List<Cookie> cookies = httpClient.getCookieStore().getCookies();
if (cookies.isEmpty()) {
Log.i(TAG, "THere are no cookies");
}
else {
for (int i = 0; i < cookies.size(); i++) {
Log.i(TAG, " - " + cookies.get(i).toString());
}
}
HttpPost httpPost = new HttpPost(LOGIN);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("username", "MyUserName"));
nvps.add(new BasicNameValuePair("password", "MyPassword"));
httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
Log.i(TAG, "The last header's value is.... " + response.getAllHeaders().length);
response = httpClient.execute(httpPost);
entity = response.getEntity();
Log.i(TAG, "Login form get: " + response.getStatusLine());
if (entity != null) {
entity.consumeContent();
}
Log.i(TAG, "Post login cookies: ");
cookies = httpClient.getCookieStore().getCookies();
if (cookies.isEmpty()) {
Log.i(TAG, "No Cookies");
}
else {
for (int i = 0; i < cookies.size(); i++) {
Log.i(TAG, " - " + cookies.get(i).toString());
}
}
httpClient.getConnectionManager().shutdown();
这段代码没有返回任何错误,但只获取了一个cookie,我认为我需要另一个COOKIE——CASTGC cookie......
我希望有经验的人能够理解上面的图表,并告诉我是否正确。
谢谢阅读。