1

I want to login to https://spps.getalma.com

Below is the form source

<form id="login-form" action="/login" method="post" autocomplete="off" class="pure-form pure-form-stacked login-form">
    <label>
        Username
        <input name="username" type="text" class="pure-input-1" placeholder="Username" value="" required="" autofocus="">
    </label>

    <label>
        Password
        <input name="password" type="password" class="pure-input-1" placeholder="Password" value="" required="">
    </label>
    <button type="submit" class="pure-button pure-button-primary">Login</button>
</form>

I am trying this

public String getString(String username, String password) {
    Connection.Response loginForm = null;
    Document document = null;
    try {
        loginForm = Jsoup.connect("https://spps.getalma.com/").method(Connection.Method.GET).execute();
        document = Jsoup.connect("https://spps.getalma.com/login")
                .data("cookieexists", "false").data("username", username)
                .data("password", password).cookies(loginForm.cookies()).post();
    } catch (IOException e) {
        e.printStackTrace();
    }

    String temp = document.title();
    return temp;
}

But when I start the app and execute this method, my app just shuts down. I am guessing that it doesn't login properly and I don't know what I should do to make it work..

You can use this username and password to login
ID: paul.kim
Password: Dvjpp;[sddeptfdr,rdyrt1

It says this is Caused by: android.os.NetworkOnMainThreadException

Please help me. Thanks

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

0

call below class using these way

    new AsyncCaller().execute();

 private class AsyncCaller extends AsyncTask<Void, Void, String>
    {
        ProgressDialog pdLoading = new ProgressDialog(AsyncExample.this);

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

            //this method will be running on UI thread
            pdLoading.setMessage("Loading...");
            pdLoading.show();
        }
        @Override
        protected String doInBackground(Void... params) {

           String result= getString("your username","your password")


            return result;
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
         pdLoading.dismiss();
        Toast.make(context,result,Toas.LENGTH_SHORT).show();
        }

        }
    }
Rajesh N
  • 6,198
  • 2
  • 47
  • 58