[android-developers] Http post and get

2012-01-20 Thread n3d!m
My application connects to website which requires username and password. 
After POST is done http GET cannot access next page after login.
After searching for solution I cam e to conclusion I need to send cookie 
with http POST.
Tried this 

DefaultHttpClient mHttpClient = new DefaultHttpClient();
BasicHttpContext mHttpContext = new BasicHttpContext();
CookieStore mCookieStore  = new BasicCookieStore();
mHttpContext.setAttribute(ClientContext.COOKIE_STORE, mCookieStore);

HttpResponse response = mHttpClient.execute(mRequest, mHttpContext);

But it doesnt work.
Other examples shows usage of
httpclient.getCookieStore().getCookies();

My problem is there is no method getCookieStore in http client.

-- 
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