我想发布EmailID
并Password
使用AsyncTask
并获得响应 True 或 false,如何做到这一点。我们正在使用json
. 我看过一些链接,但无法理解。下面是我的代码。提前致谢。
private class GetLoginDataTask extends AsyncTask<Void, Void, String[]> {
@Override
protected void onPreExecute() {
super.onPreExecute();
m_ProgressDialog = ProgressDialog.show(Login.this, "Please wait..", "Retrieving data ...", true);
m_ProgressDialog.setContentView(R.layout.progress);
m_ProgressDialog.show();
}
@Override
protected String[] doInBackground(Void... params) {
// Simulates a background job.
String mStrings[] = { "" };
try {
HttpClient client = new DefaultHttpClient();
String postURL = "http://192.168.0.126/MeritServices/MeritService.svc/Login";
HttpPost post = new HttpPost(postURL);
List<NameValuePair> param = new ArrayList<NameValuePair>();
param.add(new BasicNameValuePair("EmailID", strEmail));
param.add(new BasicNameValuePair("Password", strPassword));
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(param, HTTP.UTF_8);
post.setEntity(ent);
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();
if (resEntity != null) {
Log.i("RESPONSE :::: ", EntityUtils.toString(resEntity));
}
} catch (Exception e) {
e.printStackTrace();
Log.i("ERROR ::: ", e.toString());
}
return mStrings;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String[] result) {
System.out.println("ProgressBar Dismiss");
super.onPostExecute(result);
m_ProgressDialog.dismiss();
}
}