Skip to content Skip to sidebar Skip to footer

Using Jsoup Post Method In Android

I want something like that.i have a button and 2 textbox when user put their username and password and then click on login button then login action will be performed and then welco

Solution 1:

i think it is threading problem. because your internet request is on main UI-Thread. test this:

privateclassAsyncExecutionextendsAsyncTask<Void, Void, Void>{
    boolean tracker = false;
    String s = "";
    @Override
    protectedVoid doInBackground(Void... params) {
       try {
           Connection.Response res = Jsoup.connect("http://www.kuetlive.com/wp-login.php")
                        .data("log", "abcd", "pwd", "12345", "wp-submit", "প্রবেশ", "redirect_to", "http://www.kuetlive.com/wp-admin/", "testcookie", "1")
                        .method(Method.POST)
                        .settimeout(60000)//time set for the connection 1 min
                        .execute();
                Map<String, String> cookies = res.cookies();

                Document doc2 = Jsoup
                    .connect("http://www.kuetlive.com/wp-admin/profile.php")
                    .cookies(cookies)
                    .get();

                s = doc2.text().toString();
                tracker = true;

       } catch (Exception e) {
           // TODO Auto-generated catch block
           Log.e("tag", e.toString());
           tracker = false;

       }
     }
  --- // }  // --- i add this by mistake, delete this

    @Override
    protectedvoid onPostExecute(Void result) {
       if(tracker){
            t.setText(s);
       }else{
            t.setText("no");
       }
    }

}

and call it as

new AsyncExecution().execute();

Edited: you cannot perform an internet request on main UI-Thread. that is why u need a different thread. now u could implement a simple thread instead of AsyncTask. then why i suggest u to use AyncTask. the answer is, u cannot update your UI from a simple Thread. that is why u need AsyncTask, because AsyncTask gives u flexibility to update UI but execute your method in different Thread beside UI-Thread.

Post a Comment for "Using Jsoup Post Method In Android"