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?

Mathias Mariman
  • 43
  • 1
  • 1
  • 7

2 Answers2

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

Jeroen Dierckx
  • 133
  • 1
  • 6
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

Community
  • 1
  • 1
Numb Gk
  • 51
  • 2