vendredi 1 septembre 2017

aspx webpage log in via android app using android studio

I'm trying to create an Android app which will access personal student data from the college website.

I have imported Jsoup library to my project and I try to work with it.

I'm unable to send successful POST request. I'm not familiar with web development so this is very new to me and I hope someone could explain to me how to send the login data at first and afterwards how to retrieve the data from the website.

The login url is: http://ift.tt/2woYKhg. I have tried to find the target url after logging in but failed. The url stays the same and I couldn't find anything related with google network debugger.

Here is the login function in my app:

  public void signIn(View v) {
    final EditText username = (EditText)findViewById(R.id.username);
    final EditText password = (EditText)findViewById(R.id.password);
    final String R1C1 = username.getText().toString();
    final String R1C2 = password.getText().toString();

    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            try  {
                //With this you login and a session is created
                Connection.Response res = Jsoup.connect("http://ift.tt/2woYKhg")
                        .data("R1C1", R1C1, "R1C2", R1C2)
                        .method(Connection.Method.POST)
                        .execute();

                //This will get you cookies
                Map<String, String> loginCookies = res.cookies();

                //Here you parse the page that you want. Put the url that you see when you have logged in
                Document doc = Jsoup.connect("http://ift.tt/2woYKhg")
                        .cookies(loginCookies)
                        .get();
            } catch (Exception e) {
                Log.i(TAG,e.toString());
            }
        }
    });
    thread.start();
}

I tried to inspect the website source code and found this relevant:

<div class="col-md-4 dir-rtl">
    <!--Reg Block-->        
    <div class="reg-block reg-block-Right">
                    <div class="input-group margin-bottom-10">
            <span class="input-group-addon"><span class="fa fa-user color-green fa-lg"></span></span>
            <label for="R1C1"  class="sr-only">משתמש:</label>
            <input type="text" name="R1C1" id="R1C1" autocomplete="off" dir="rtl" class="form-control NumbersOnly" placeholder="מספר תעודת זהות">           
        </div>
        <div class="input-group margin-bottom-10">
            <span class="input-group-addon"><span class="fa fa-lock color-green fa-lg"></span></span>
            <label for="R1C2"  class="sr-only">סיסמה:</label>
            <input type="password" name="R1C2" id="R1C2" dir="rtl" autocomplete="off" class="form-control" placeholder="סיסמה" readonly>
        </div>


        <div class="row">

            <div class="col-md-10 col-md-offset-1">


                <button type="submit" class="btn-u btn-block">כניסה למערכת</button>
            </div>
        </div>

As you can see, they named username field as R1C1 and password field as R1C2. The submit button is right below. Furthermore, I found this relevant:

<form ACTION="fireflyweb.aspx" autocomplete="off"
     ENCtype="multipart/form-data"
     METHOD="post"
     id="mainForm"
     onsubmit="return onSubmitForm();">

    <input type="hidden" name="PRGNAME" value="LoginValidation">
<input type="hidden" name="R1C5" id="R1C5" value="">

<input type="hidden" name="ARGUMENTS" value="R1C1,R1C2,-AH,-A,-N,-N,-N,-A,R1C5">

what are these arguments? R1C1 and R1C2 are username and password but what are the rest? how do I pass them in POST request?

Any help would be appreciated.




Aucun commentaire:

Enregistrer un commentaire