2

I just created an MVC4 WebApplication. This application is using a database (created by CodeFirst) which contains the user info (aspnet Membership) and all the other info.

I'm now trying to make an Android app which uses the same database as the MVC4 Webapplication. But I have no clue how I can implement the login system.

I was thinking about sending a post request to the server (local for the moment) with the username and password. (will be encrypted later). But I have no clue how I can do this.

Can anyone help me out with the login system? Should I make some changes to my Webapplication to achieve my goal?

Thanks in advance !


UPDATE I now tried the following: I just wrote the following function which I run when I press my button

android:onClick="login"

My java function:

public void login(){
    String userName = "Isf";
    String password = "admin123!";

    HttpClient httpClient = new DefaultHttpClient();

    //I run my MVC Application local
    //Logon page: http://localhost:2657/Account/LogOn
    HttpPost httpPost = new HttpPost("http://10.0.2.2/Account/LogOn");

    try {
          List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);

          nameValuePairs.add(new BasicNameValuePair("username", userName));
          nameValuePairs.add(new BasicNameValuePair("password", password));

          httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
          // Response from the Http Request
          HttpResponse response = httpClient.execute(httpPost);

       } catch (IOException e) {
          Log.e("Exception", "IOException", e);
       } catch (Exception e) {
          Log.e("Exception", "General Exception", e);
       }
}

But when I run my MVC project and I press my login button on Android, I get the following message: "The application login (proces com.example.login) has stopped unexpectedly. Please try again." (I tried it with my phone, and with the emulator) Does anyone know what I'm doing wrong?

2
  • What kind of Android app are you planning? A java application or a mobile website? Commented May 7, 2013 at 12:32
  • I'm planning to create a java application. Commented May 8, 2013 at 10:57

2 Answers 2

2

Are you using asyncTasks? Requests cant be send in the main thread, asynctask is going to create a new thread. There is some good documentation on developer site from android: asynctask

Sign up to request clarification or add additional context in comments.

Comments

0

You can use HTTP to send and receive data http://www.jiahaoliuliu.com/2012/04/android-http-client-login.html Make an HTTP request with android http://developer.android.com/reference/org/apache/http/client/HttpClient.html

2 Comments

Thanks for the info, I'm going to try this later today!
I tried it, but it failed. Please review my code in the updated question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.