I need to authenticate username and password with my website which provides Session Cookies.
I am collecting username and password from the EditText on the form and passing it onto authenticate session.
@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);
}
The username and password are then checked if they are correct to return the session cookie.
public static String getSessionCookie(String username, String password) {
String login_url = "http://www.myexperiment.org/session/create";
URLConnection connection = null;
String sessionXML = "<session><username>" + username +
"</username><passsword>" + password +
"</password></session>";
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;
}
In the Manifest file I have permission set.
There are no errors but NULL is retuned at the end. I have checked (in debug) the username and password which are correct being passed in the function.
I hope someone can help here.
Thanks.