Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7596343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:53:46+00:00 2026-05-30T21:53:46+00:00

I need to authenticate username and password with my website which provides Session Cookies.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:53:47+00:00Added an answer on May 30, 2026 at 9:53 pm

    For anyone interested; here is the working code. Its an exert of it showing the method.

    try
    {
        URL url = new URL(login_url);
        connection = (HttpURLConnection) url.openConnection();  
    
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/xml");
    
        OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
        out.write(sessionXML);
        out.flush();
        out.close();
    
        String headerName = "";
    
        for (int i = 1; (headerName = connection.getHeaderFieldKey(i)) != null; i++)
        {       
            if(headerName.equals("Set-Cookie"))
            {
                cookieValue = connection.getHeaderField(i);         
            }
        }
    } 
    catch (Exception e)
    {
        e.printStackTrace();
    }
    finally
    {
        if(connection != null)
            connection.disconnect();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i try to code a login form which passes username and password to a
i have string username and string password. i need to authenticate the user and
Hi All Nightowls out there :), I need to authenticate username and password provided
I have an AuthenticationManager.authenticate(username,password) method that gets called in someMethod of a SomeService under
i need to authenticate my services with username and passwor i have try this
I have a client, which communicates to a TCP server. I store a username/password
I have an sql azure database. I need an silverlight application with username/password authentication
I have a project requirement where I need to authenticate against ActiveDirectory in a
What is the best practice when you need to authenticate specific OperationContracts , while
I want to authenticate users against our AD so I understand that I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.