Код: Выделить всё
@Override
public void onClick(View v) {
String Username = username.getText().toString();
String Password = password.getText().toString();
String value = LoginAuthenticate.getSessionCookie(Username, Password);
// This is just check what session value is brought back
username.setText(value);
}
< /code>
Имя пользователя и пароль проверяются, если они правы, чтобы вернуть файловые файлы сеанса.public static String getSessionCookie(String username, String password) {
String login_url = "http://www.example.com/session/create";
URLConnection connection = null;
String sessionXML = "" + username + "" + password + "";
String cookieValue = null;
try {
URL url = new URL(login_url);
connection = url.openConnection();
connection.setRequestProperty("Content-Type", "application/xml");
connection.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write(sessionXML);
out.close();
} catch (Exception e) {
e.printStackTrace();
return null;
}
String headerName = null;
for (int i = 0; (headerName = connection.getHeaderFieldKey(i)) != null; i++) {
if (headerName.equals("Set-Cookie")) {
cookieValue = connection.getHeaderField(i);
}
}
// return connection.getHeaderField("Set-Cookie:");
return cookieValue;
}
< /code>
В файле манифеста у меня есть следующие разрешения: < /p>
Подробнее здесь: https://stackoverflow.com/questions/941 ... on-cookies