I want to get an .ics file from a webpage but there I need to login.
I’m able to login with the following code:
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://ipool.ba-berlin.de/stundenplaene.anzeige.php?faculty=15&course=6&type=html");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
System.out.println("Login form get: " + response.getStatusLine());
if (entity != null) {
entity.consumeContent();
}
System.out.println("Initial set of cookies:");
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());
}
}
HttpPost httpost = new HttpPost("http://ipool.ba-berlin.de/main.php?action=login");
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("FORM_LOGIN_NAME", "MY_USERNAME"));
nvps.add(new BasicNameValuePair("FORM_LOGIN_PASS", "MY_PASSWORD"));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = httpclient.execute(httpost);
entity = response.getEntity();
System.out.println("Login form get: " + response.getStatusLine());
if (entity != null) {
entity.consumeContent();
}
System.out.println("Post logon cookies:");
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());
}
}
httpclient.getConnectionManager().shutdown();
But after my login, I don’t know how to get the content of my file. How can I make it possible?
Thanks a lot!
If i understand you question after login you should request resources (file url) with your session cookie.
try something like this
You have already managed to login, so you should have recieved session cookie in response,
i see it in your code, now you have to make new http request to url where you file is, but server side need to validate that you are already logged in, so it stored data about you in session object based on id you have recieved in response as cookie named JSESSIONID , you need to pass that cookie together with new request, the example creates new cookie you can pass recieved cookie directly