Re: [android-developers] Submit username and password to website

2012-01-20 Thread TreKing
On Tue, Jan 17, 2012 at 5:45 AM, n3d!m  wrote:

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

http://bit.ly/Aa2O3z
This has nothing to do with Android.

-
TreKing  - Chicago
transit tracking app for Android-powered devices

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

[android-developers] Submit username and password to website

2012-01-20 Thread n3d!m
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 userData=new 
ArrayList(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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en