Php 没有得到回应
我正在创建一个应用程序,其中我向我的web服务发送了一些参数,现在它正在本地主机上运行,并向我提供json响应。不知何故,它在这一行之后不起作用HttpResponse HttpResponse=httpClient.execute(httpPost)。谁能帮忙吗。 另外,我的网络服务运行得非常好 test_class.javaPhp 没有得到回应,php,android,Php,Android,我正在创建一个应用程序,其中我向我的web服务发送了一些参数,现在它正在本地主机上运行,并向我提供json响应。不知何故,它在这一行之后不起作用HttpResponse HttpResponse=httpClient.execute(httpPost)。谁能帮忙吗。 另外,我的网络服务运行得非常好 test_class.java package com.vitarkasolutions.tracker; import java.io.IOException; import java.io.I
package com.vitarkasolutions.tracker;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.google.gson.Gson;
public class test_class extends Activity{
final static String url = "http://10.0.2.2/tracker/index.php" ;
String xyz ="";
String tag ="login";
String name="varun";
String email="varun@gmail.com";
int lat= 10;
int lang = 20;
int phone_no= 10;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
Button btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
registerUser(name, email, tag, phone_no, lat, lang);
}
});
}
@SuppressWarnings("unchecked")
public void registerUser(String name, String email,String register_tag, int phone_no ,int lat , int lang )
{
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tag", register_tag));
params.add(new BasicNameValuePair("name", name));
params.add(new BasicNameValuePair("email", email));
params.add(new BasicNameValuePair("phone_no",String.valueOf(phone_no)));
params.add(new BasicNameValuePair("lat",String.valueOf(lat) ));
params.add(new BasicNameValuePair("lang", String.valueOf(lang)));
try {
parsing data = new parsing();
data.execute(params);
//AsyncTask parsing =new parsing().execute(params);
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public class parsing extends AsyncTask<List<? extends NameValuePair>, Void, Void> {
// Making HTTP request
@Override
protected Void doInBackground(List<? extends NameValuePair>... params) {
// TODO Auto-generated method stub
Log.e("tag", "parse function called");
try{
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
Log.d("tag", "post");
httpPost.setEntity(new UrlEncodedFormEntity(params[0]));
Log.d("tag", "entity");
HttpResponse httpResponse = httpClient.execute(httpPost);
Log.d("tag", "response");
final int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK)
{
Log.w(getClass().getSimpleName(), "Error " + statusCode + " for URL " + url);
Log.d("not Connected", "connected");
}else{
Log.d("Connected", "connected");
}
Log.d("Con", "connected");
HttpEntity httpEntity = httpResponse.getEntity();
InputStream is = httpEntity.getContent();
Reader Reader = new InputStreamReader(is);
Log.e("tag2", is.toString());
Gson gson = new Gson();
user user = gson.fromJson(Reader,user.class);
Log.e("tag3", "done");
Log.e("tag4", user.toString());
Log.e("tag4", user.name);
Log.d("tag4", user.email);
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
}
package com.vitarkasolutions.tracker;
导入java.io.IOException;
导入java.io.InputStream;
导入java.io.InputStreamReader;
导入java.io.Reader;
导入java.io.UnsupportedEncodingException;
导入java.util.ArrayList;
导入java.util.List;
导入org.apache.http.HttpEntity;
导入org.apache.http.HttpResponse;
导入org.apache.http.HttpStatus;
导入org.apache.http.NameValuePair;
导入org.apache.http.client.ClientProtocolException;
导入org.apache.http.client.entity.UrlEncodedFormEntity;
导入org.apache.http.client.methods.HttpPost;
导入org.apache.http.impl.client.DefaultHttpClient;
导入org.apache.http.message.BasicNameValuePair;
导入android.app.Activity;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.Button;
导入com.google.gson.gson;
公共类测试类扩展活动{
最终静态字符串url=”http://10.0.2.2/tracker/index.php" ;
字符串xyz=“”;
String tag=“login”;
String name=“varun”;
字符串电子邮件=”varun@gmail.com";
int-lat=10;
int lang=20;
int phone_no=10;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
按钮btn=(按钮)findViewById(R.id.button1);
btn.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
注册者(姓名、电子邮件、标签、电话号码、lat、LAG);
}
});
}
@抑制警告(“未选中”)
公共无效注册表服务器(字符串名称、字符串电子邮件、字符串注册表标签、整数电话号码、整数lat、整数语言)
{
//建筑参数
List params=new ArrayList();
参数添加(新的BasicNameValuePair(“标记”,寄存器_标记));
参数添加(新的BasicNameValuePair(“名称”),名称);
参数添加(新的BasicNameValuePair(“电子邮件”),电子邮件);
params.add(新的BasicNameValuePair(“电话号码”,String.valueOf(电话号码));
参数add(新的BasicNameValuePair(“lat”,String.valueOf(lat)));
添加(新的BasicNameValuePair(“lang”,String.valueOf(lang)));
试一试{
解析数据=新解析();
数据。执行(参数);
//AsyncTask解析=新建解析().execute(params);
}捕获(非法状态){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
公共类解析扩展了异步任务
下载时使用:
使用以下过程添加jar文件:-
右键单击项目---->Build Path---->Configure Build Path…-->在左侧,您必须选择Java Build Path---->Libraries---->Add External jar---->ok---->ok
希望这能解决问题
package com.example.login;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import com.example.login.ConnectionDetector;
public class MainActivity extends Activity
{
public EditText uname,pwd;
ImageView btnlog1;
public Button btncancel1;
public String db_select;
String mUname;
String mPwd;
String temp;
Intent intObj;
Intent intent = null;
Boolean isInternetPresent = false;
ConnectionDetector cd;
private String SERVICE_URL = "http://100.2.1.97:8080/Database/path";
//private String SERVICE_URL = "http://10.1.1.138:8080/Database/path";
private final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
MainActivity.this.setContentView(R.layout.activity_main);
uname=(EditText)findViewById(R.id.editText1);
pwd=(EditText)findViewById(R.id.editText2);
btnlog1=(ImageView)findViewById(R.id.login);
//btncancel1=(Button)findViewById(R.id.button2);
//SERVICE_URL=ServerURL.URL+"/msd";
btnlog1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
mUname=uname.getText().toString();
mPwd=pwd.getText().toString();
// display("Login clicked");
if(!mUname.equalsIgnoreCase("") &&
!mPwd.equalsIgnoreCase(""))
{
cd = new
ConnectionDetector(getApplicationContext());
isInternetPresent = cd.isConnectingToInternet();
//Toast.makeText(MainActivity.this,
isInternetPresent, Toast.LENGTH_LONG).show();
if(isInternetPresent)
{
try
{
validat_user(mUname,mPwd);
}
catch(Exception e)
{
display("Network error.\nPlease check with
your network settings.");
uname.setText("");
pwd.setText("");
}
}
else
{
display("No Internet Connection...");
}
}
else
{
display("Please enter the data in all Required
fields...");
}
}
});
}
public void display(String msg)
{
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_LONG).show();
}
private void validat_user(String stg1, String stg2)
{
db_select=stg1;
WebServiceTask wst = new WebServiceTask(WebServiceTask.POST_TASK, this, "Login
in progress...");
wst.addNameValuePair("EMP_ID", stg1);
wst.addNameValuePair("EMP_PWD", stg2);
wst.execute(new String[] { SERVICE_URL });
}
@SuppressWarnings("deprecation")
public void no_net()
{
display( "No Network Connection");
final AlertDialog alertDialog = new
AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("No Internet Connection");
alertDialog.setMessage("You don't have internet connection.\nElse please
check the Internet Connection Settings.");
//alertDialog.setIcon(R.drawable.error_info);
alertDialog.setCancelable(false);
alertDialog.setButton("Close", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
alertDialog.cancel();
MainActivity.this.finish();
System.exit(0);
}
});
alertDialog.setButton2("Use Local DataBase", new
DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
display( "Accessing local DataBase.....");
alertDialog.cancel();
}
});
alertDialog.show();
}
private class WebServiceTask extends AsyncTask<String, Integer, String> {
public static final int POST_TASK = 1;
private static final String TAG = "WebServiceTask";
// connection timeout, in milliseconds (waiting to connect)
private static final int CONN_TIMEOUT =3000;
// socket timeout, in milliseconds (waiting for data)
private static final int SOCKET_TIMEOUT = 5000;
private int taskType = POST_TASK;
private Context mContext = null;
private String processMessage = "Processing...";
private ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
private ProgressDialog pDlg = null;
public WebServiceTask(int taskType, Context mContext, String processMessage) {
this.taskType = taskType;
this.mContext = mContext;
this.processMessage = processMessage;
}
public void addNameValuePair(String name, String value) {
params.add(new BasicNameValuePair(name, value));
}
@SuppressWarnings("deprecation")
private void showProgressDialog() {
pDlg = new ProgressDialog(mContext);
pDlg.setMessage(processMessage);
pDlg.setProgressDrawable(mContext.getWallpaper());
pDlg.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pDlg.setCancelable(false);
pDlg.show();
}
@Override
protected void onPreExecute() {
showProgressDialog();
}
protected String doInBackground(String... urls) {
String url = urls[0].toString();
String result = "";
HttpResponse response = doResponse(url);
if (response == null) {
return result;
} else {
try {
result = inputStreamToString(response.getEntity().getContent());
} catch (IllegalStateException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
} catch (IOException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
catch(Exception e)
{
Log.e(TAG, e.getLocalizedMessage(), e);
}
}
return result;
}
@Override
protected void onPostExecute(String response) {
handleResponse(response);
pDlg.dismiss();
}
// Establish connection and socket (data retrieval) timeouts
private HttpParams getHttpParams() {
HttpParams htpp = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(htpp, CONN_TIMEOUT);
HttpConnectionParams.setSoTimeout(htpp, SOCKET_TIMEOUT);
return htpp;
}
private HttpResponse doResponse(String url) {
// Use our connection and data timeouts as parameters for our
// DefaultHttpClient
HttpClient httpclient = new DefaultHttpClient(getHttpParams());
HttpResponse response = null;
try {
switch (taskType) {
case POST_TASK:
HttpPost httppost= new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(params));
response = httpclient.execute(httppost);
break;
}
}
catch (Exception e) {
// display("Remote DataBase can not be connected.\nPlease check network
connection.");
Log.e(TAG, e.getLocalizedMessage(), e);
return null;
}
return response;
}
private String inputStreamToString(InputStream is) {
String line = "";
StringBuilder total = new StringBuilder();
// Wrap a BufferedReader around the InputStream
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
try {
// Read response until the end
while ((line = rd.readLine()) != null) {
total.append(line);
}
} catch (IOException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
catch(Exception e)
{
Log.e(TAG, e.getLocalizedMessage(), e);
}
// Return full string
return total.toString();
}
}
public void handleResponse(String response)
{
//display("Response:"+response);
if(!response.equalsIgnoreCase(""))
{
JSONObject jso;
try {
jso = new JSONObject(response);
String status = jso.getString("status");
// display("Welcome : "+UName);
if( status.equalsIgnoreCase("") || status==null ||
status.equalsIgnoreCase("Failed"))
{
reset();
}
else
{
//display(status);
intObj=new
Intent(MainActivity.this,pdf.class);
startActivity(intObj);
MainActivity.this.finish();
}
}
catch (JSONException e1) {
// TODO Auto-generated catch block
Log.e(TAG, e1.getLocalizedMessage(), e1);
}
catch(Exception e)
{
Log.e(TAG, e.getLocalizedMessage(), e);
}
}
else
{
display("Could not able to reach Server!");
}
}
public void reset()
{
display("Entered User ID / Password is incorrect.\nPlease enter valid User ID &
Password.");
pwd.setText("");
uname.setText("");
}
}
package com.example.login;
导入java.io.BufferedReader;
导入java.io.IOException;
导入java.io.InputStream;
导入java.io.InputStreamReader;
导入java.util.ArrayList;
导入org.apache.http.HttpResponse;
导入org.apache.http.NameValuePair;
导入org.apache.http.client.HttpClient;
导入org.apache.http.client.entity.UrlEncodedFormEntity;
导入org.apache.http.client.methods.HttpGet;
导入org.apache.http.client.methods.HttpPost;
导入org.apache.http.client.methods.HttpPut;
导入org.apache.http.impl.client.DefaultHttpClient;
导入org.apache.http.message.BasicNameValuePair;
导入org.apache.http.params.BasicHttpParams;
导入org.apache.http.params.HttpConnectionParams;
导入org.apache.http.params.HttpParams;
导入org.json.JSONException;
导入org.json.JSONObject;
导入android.app.Activity;
导入android.app.AlertDialog;
导入android.app.ProgressDialog;
导入android.content.Context;
导入android.content.DialogInterface;
导入android.content.Intent;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.ImageView;
导入android.widget.Toast;
导入com.example.login.ConnectionDetector;
公共类MainActivity扩展了活动
{
公共编辑文本uname,pwd;
ImageView btnlog1;
公共按钮BTNCENCEL1;
公共字符串db_select;
字符串名称;
字符串mPwd;
字符串温度;
意图输入北京;
意向=无效;
布尔值isInternetPresent=false;
连接检测器cd;
专用字符串服务\u URL=”http://100.2.1.97:8080/Database/path";
//专用字符串服务\u URL=”http://10.1.1.138:8080/Database/path";
私有最终字符串TAG=“MainActivity”;
@凌驾
创建时受保护的void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
MainActivity.this.setContentView(R.layout.activity_main);
uname=(EditText)findViewById(R.id.editText1);
pwd=(EditText)findViewById(R.id.editText2);
btnlog1=(ImageView)findViewById(R.id.login);
//BTNCENCEL1=(按钮)findViewById(R.id.button2);
//服务URL=ServerURL.URL+“/msd”;
btnlog1.setOnClickListener(新视图.OnClickListener()
{
@凌驾
公共void onClick(视图v)
{
mUname=uname.getText().toString();
mPwd=pwd.getText().toString();
//显示(“点击登录”);
如果(!mUname.equalsIgnoreCase(“”)&&
!mPwd.equalsIgnoreCase(“”)
{
cd=新
连接检测器(GetApplicationContent)
package com.example.login;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import com.example.login.ConnectionDetector;
public class MainActivity extends Activity
{
public EditText uname,pwd;
ImageView btnlog1;
public Button btncancel1;
public String db_select;
String mUname;
String mPwd;
String temp;
Intent intObj;
Intent intent = null;
Boolean isInternetPresent = false;
ConnectionDetector cd;
private String SERVICE_URL = "http://100.2.1.97:8080/Database/path";
//private String SERVICE_URL = "http://10.1.1.138:8080/Database/path";
private final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
MainActivity.this.setContentView(R.layout.activity_main);
uname=(EditText)findViewById(R.id.editText1);
pwd=(EditText)findViewById(R.id.editText2);
btnlog1=(ImageView)findViewById(R.id.login);
//btncancel1=(Button)findViewById(R.id.button2);
//SERVICE_URL=ServerURL.URL+"/msd";
btnlog1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
mUname=uname.getText().toString();
mPwd=pwd.getText().toString();
// display("Login clicked");
if(!mUname.equalsIgnoreCase("") &&
!mPwd.equalsIgnoreCase(""))
{
cd = new
ConnectionDetector(getApplicationContext());
isInternetPresent = cd.isConnectingToInternet();
//Toast.makeText(MainActivity.this,
isInternetPresent, Toast.LENGTH_LONG).show();
if(isInternetPresent)
{
try
{
validat_user(mUname,mPwd);
}
catch(Exception e)
{
display("Network error.\nPlease check with
your network settings.");
uname.setText("");
pwd.setText("");
}
}
else
{
display("No Internet Connection...");
}
}
else
{
display("Please enter the data in all Required
fields...");
}
}
});
}
public void display(String msg)
{
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_LONG).show();
}
private void validat_user(String stg1, String stg2)
{
db_select=stg1;
WebServiceTask wst = new WebServiceTask(WebServiceTask.POST_TASK, this, "Login
in progress...");
wst.addNameValuePair("EMP_ID", stg1);
wst.addNameValuePair("EMP_PWD", stg2);
wst.execute(new String[] { SERVICE_URL });
}
@SuppressWarnings("deprecation")
public void no_net()
{
display( "No Network Connection");
final AlertDialog alertDialog = new
AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("No Internet Connection");
alertDialog.setMessage("You don't have internet connection.\nElse please
check the Internet Connection Settings.");
//alertDialog.setIcon(R.drawable.error_info);
alertDialog.setCancelable(false);
alertDialog.setButton("Close", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
alertDialog.cancel();
MainActivity.this.finish();
System.exit(0);
}
});
alertDialog.setButton2("Use Local DataBase", new
DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
display( "Accessing local DataBase.....");
alertDialog.cancel();
}
});
alertDialog.show();
}
private class WebServiceTask extends AsyncTask<String, Integer, String> {
public static final int POST_TASK = 1;
private static final String TAG = "WebServiceTask";
// connection timeout, in milliseconds (waiting to connect)
private static final int CONN_TIMEOUT =3000;
// socket timeout, in milliseconds (waiting for data)
private static final int SOCKET_TIMEOUT = 5000;
private int taskType = POST_TASK;
private Context mContext = null;
private String processMessage = "Processing...";
private ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
private ProgressDialog pDlg = null;
public WebServiceTask(int taskType, Context mContext, String processMessage) {
this.taskType = taskType;
this.mContext = mContext;
this.processMessage = processMessage;
}
public void addNameValuePair(String name, String value) {
params.add(new BasicNameValuePair(name, value));
}
@SuppressWarnings("deprecation")
private void showProgressDialog() {
pDlg = new ProgressDialog(mContext);
pDlg.setMessage(processMessage);
pDlg.setProgressDrawable(mContext.getWallpaper());
pDlg.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pDlg.setCancelable(false);
pDlg.show();
}
@Override
protected void onPreExecute() {
showProgressDialog();
}
protected String doInBackground(String... urls) {
String url = urls[0].toString();
String result = "";
HttpResponse response = doResponse(url);
if (response == null) {
return result;
} else {
try {
result = inputStreamToString(response.getEntity().getContent());
} catch (IllegalStateException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
} catch (IOException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
catch(Exception e)
{
Log.e(TAG, e.getLocalizedMessage(), e);
}
}
return result;
}
@Override
protected void onPostExecute(String response) {
handleResponse(response);
pDlg.dismiss();
}
// Establish connection and socket (data retrieval) timeouts
private HttpParams getHttpParams() {
HttpParams htpp = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(htpp, CONN_TIMEOUT);
HttpConnectionParams.setSoTimeout(htpp, SOCKET_TIMEOUT);
return htpp;
}
private HttpResponse doResponse(String url) {
// Use our connection and data timeouts as parameters for our
// DefaultHttpClient
HttpClient httpclient = new DefaultHttpClient(getHttpParams());
HttpResponse response = null;
try {
switch (taskType) {
case POST_TASK:
HttpPost httppost= new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(params));
response = httpclient.execute(httppost);
break;
}
}
catch (Exception e) {
// display("Remote DataBase can not be connected.\nPlease check network
connection.");
Log.e(TAG, e.getLocalizedMessage(), e);
return null;
}
return response;
}
private String inputStreamToString(InputStream is) {
String line = "";
StringBuilder total = new StringBuilder();
// Wrap a BufferedReader around the InputStream
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
try {
// Read response until the end
while ((line = rd.readLine()) != null) {
total.append(line);
}
} catch (IOException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
catch(Exception e)
{
Log.e(TAG, e.getLocalizedMessage(), e);
}
// Return full string
return total.toString();
}
}
public void handleResponse(String response)
{
//display("Response:"+response);
if(!response.equalsIgnoreCase(""))
{
JSONObject jso;
try {
jso = new JSONObject(response);
String status = jso.getString("status");
// display("Welcome : "+UName);
if( status.equalsIgnoreCase("") || status==null ||
status.equalsIgnoreCase("Failed"))
{
reset();
}
else
{
//display(status);
intObj=new
Intent(MainActivity.this,pdf.class);
startActivity(intObj);
MainActivity.this.finish();
}
}
catch (JSONException e1) {
// TODO Auto-generated catch block
Log.e(TAG, e1.getLocalizedMessage(), e1);
}
catch(Exception e)
{
Log.e(TAG, e.getLocalizedMessage(), e);
}
}
else
{
display("Could not able to reach Server!");
}
}
public void reset()
{
display("Entered User ID / Password is incorrect.\nPlease enter valid User ID &
Password.");
pwd.setText("");
uname.setText("");
}
}