请有人帮忙吗?我学会用android创建一个登录应用程序。我坚持使用httpclient.execute
结果始终为null n跳过httpclient.execute
这是我的代码:
try {
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://example.com/myandroidsite/user_validate.php");
//Add data
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("UserMail",usr.trim()));
nameValuePairs.add(new BasicNameValuePair("Password",pass.trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//Execute HTTP Post Request
respone = httpclient.execute(httppost);
inputstream = respone.getEntity().getContent();
data = new byte[256];
buffer = new StringBuffer();
int len = 0;
while(-1 != (len = inputstream.read(data)))
{
buffer.append(new String(data, 0, len));
}
inputstream.close();
}
catch (Exception e)
{
Toast.makeText(MainActivity.this, "error "+e.toString(), Toast.LENGTH_LONG).show();
}