0

请问有人可以帮忙吗?我学会了用android创建一个登录应用程序。我坚持httpclient.execute结果总是 null n skip to catch afterhttpclient.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();
}
4

0 回答 0