在android 4.2.2 sdk上粘贴了httpclient.execute(httppost)

时间:2013-04-29 19:00:07

标签: android http client

请有人帮忙吗?我学会用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();
}

0 个答案:

没有答案