android 登录判断

原创
2013/04/22 18:10
阅读数 298
public void login() { 
        String target = "http://192.168.1.77/android/json_users/login_users.aspx"; 
        HttpPost httprequest = new HttpPost(target); 
        List<NameValuePair> paramsList = new ArrayList<NameValuePair>(); 
        paramsList.add(new BasicNameValuePair("user_name", EditText1.getText() 
                .toString())); 
        paramsList.add(new BasicNameValuePair("password", EditText2.getText() 
                .toString())); 
        try { 
            httprequest 
                    .setEntity(new UrlEncodedFormEntity(paramsList, "UTF-8")); 
            HttpClient HttpClient1 = new DefaultHttpClient(); 
            HttpResponse httpResponse = HttpClient1.execute(httprequest); 
            if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { 
                result = EntityUtils.toString(httpResponse.getEntity()); 
            } else { 
                result = "请求失败"; 
            } 

            Toast.makeText(LoginActivity.this, result, Toast.LENGTH_SHORT) 
                    .show(); 

        } catch (UnsupportedEncodingException e1) { 
            e1.printStackTrace(); 
        } catch (ClientProtocolException e) { 
            e.printStackTrace(); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 

    }

展开阅读全文
打赏
0
2 收藏
分享
加载中
更多评论
打赏
0 评论
2 收藏
0
分享
返回顶部
顶部