I am trying to post login and username to the website.
How to do that?

Here is the code:

if (v.getId()==R.id.loginBtn) {
                HttpClient client = new DefaultHttpClient();
                HttpPost post = new HttpPost("http://ius.edu.ba:8080/sis/
index.php");
                try {
                        EditText username = (EditText)
findViewById(R.id.editUsername);
                        EditText password = (EditText) 
findViewById(R.id.editPassword);

                        String enteredUsername;
                        String enteredPassword;
                        enteredUsername=username.getText().toString();
                        enteredPassword=password.getText().toString();

                        List<NameValuePair> userData=new 
ArrayList<NameValuePair>(2);
                        userData.add(new
BasicNameValuePair("username",enteredUsername));
                        userData.add(new
BasicNameValuePair("password",enteredPassword));

                        post.setEntity(new UrlEncodedFormEntity(userData));
                        HttpResponse response = client.execute(post);


                        String siteResponse;
 
siteResponse=getResponse(response.getEntity().getContent()).toString();

                        if (siteResponse.contains("Note:"))
                                Toast.makeText(getBaseContext(), "Wrong 
username or password!"
+ siteResponse, Toast.LENGTH_LONG).show();

                        else
                                Toast.makeText(getBaseContext(), "Logged in! " +
siteResponse , Toast.LENGTH_LONG).show();

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

        }

        }

private StringBuilder getResponse(InputStream stream) {
        String line = "";
        StringBuilder result = new StringBuilder();
        BufferedReader reader = new BufferedReader(new
InputStreamReader(stream));
        try {
                while ((line = reader.readLine()) != null) {
                        result.append(line);
                }
        } catch (IOException e) {
                e.printStackTrace();
        }
        return result;
}
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to