0

I am developing a android application for a third party web site which I have no control. To use that web site user must login first. Login is done in that web site using a HTML form. Login details are sent to server by POST method and action is calling a PHP file. I want to do that login using my android application. But I don't like to load the web view and display the web page. I want to enter username and password in edittext boxes and call submit button programatically.

I searched a lot, but couldn't find a answer matches with my need.

Can anyone post a complete answer or a link to a source code?

Dulaj Atapattu
  • 448
  • 6
  • 23
  • What are the expected key-value arguments for the php file? – andrewdleach Jul 03 '15 at 17:03
  • possible duplicate of [Performing login to https website via Android app](http://stackoverflow.com/questions/6443401/performing-login-to-https-website-via-android-app) – Pztar Jul 03 '15 at 17:07
  • @andrewdleach username and password – Dulaj Atapattu Jul 03 '15 at 17:47
  • you need to write webservices... try this link http://programmerguru.com/android-tutorial/android-restful-webservice-tutorial-how-to-call-restful-webservice-in-android-part-3/ – arjunkn Jul 03 '15 at 18:09

1 Answers1

0

Below is a code snippet to your question...

private static class UserLogin extends AsyncTask<Void, Integer, String> {

    protected String doInBackground(Void... userLogin) {
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("//domain//file.php?username=UN&password=&PW);

        String result;
        String userID = null;
        try {
            HttpResponse response = httpClient.execute(httpPost);
            result = EntityUtils.toString(response.getEntity());
            if (requestBuilder.jSONResultIsSuccess(result))
                userID = requestBuilder.jSONUserID(result);

        } catch (IOException | JSONException e) {
            e.printStackTrace();
        }

        return userID;
    }

You will need to modify based on your own code design but this shows the basic structure.

andrewdleach
  • 2,458
  • 2
  • 17
  • 25