0
嘿傢伙我正在處理一個項目,它處理用戶輸入用戶名和密碼,然後他們應該登錄到他們的電子郵件accounts.i've搜索網絡,但我的問題是但我想我知道如何登錄用戶,但我不知道該怎麼從那裏通過httpclient和httppost登錄到帳戶
做這裏去我的代碼部分:
private class AsyncTaskOperation extends AsyncTask <String, Void, Void>
{
private ProgressDialog Dialog = new ProgressDialog(MainActivity.this);
String ciao="";
protected void onPreExecute() {
// Display the loading spinner
Dialog.setMessage("Loading... Please wait.. ");
Dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
Dialog.setInverseBackgroundForced(false);
Dialog.setCancelable(false);
Dialog.show();
}
@Override
protected Void doInBackground(String... paramsObj) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"https://www.elenoon.ir/mail/");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("user", user.getText()
.toString()));
nameValuePairs.add(new BasicNameValuePair("pass", pass.getText()
.toString()));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse execute = httpclient.execute(httppost);
InputStream content;
content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(
content));
String s = "";
String test = "";
while ((s = buffer.readLine()) != null) {
test += s;
}
if (test.contains("U")) {
// reset field and toast
Toast.makeText(getBaseContext(), "Login Failed", Toast.LENGTH_SHORT)
.show();
} else {
// Intent intent = new Intent(MainActivity.this,Form.class);
// this.startActivity(intent);
Toast.makeText(getBaseContext(), "Login Successful",
Toast.LENGTH_SHORT).show();
}
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void unused)
{
// Close progress dialog
Dialog.dismiss();
// Do actions after end of the HTTPGet or POST Method
} // End of method onPostExecute
問題是現在我應該怎麼知道服務器已登錄用戶,然後如何使用它來顯示另一個用戶的活動,他可以看到他自己的郵件。謝謝你,我真的很需要:)))