class LoginThread implements Runnable{ @Override public void run() { String user = userName_edit.getText().toString(); String password = password_edit.getText().toString(); NameValuePair nameValuePair1 = new BasicNameValuePair("user", user); NameValuePair nameValuePair2 = new BasicNameValuePair("password",password); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(nameValuePair1); nameValuePairs.add(nameValuePair2); try { HttpEntity httpEntity = new UrlEncodedFormEntity(nameValuePairs); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(httpEntity); HttpClient httpClient = new DefaultHttpClient(); InputStream inputStream = null; HttpResponse httpResponse = httpClient.execute(httpPost); httpEntity = httpResponse.getEntity(); inputStream = httpEntity.getContent(); BufferedReader reader = new BufferedReader( new InputStreamReader(inputStream)); String result = ""; String line = ""; while ((line = reader.readLine()) != null) { result = result + line; } Log.v("result", result); } catch (UnsupportedEncodingException e) { e.printStackTrace(); Log.v("result", 3 + ""); } catch (ClientProtocolException e) { Log.v("result", 1 + ""); e.printStackTrace(); } catch (IOException e) { Log.v("result", 2 + ""); e.printStackTrace(); } } }
其中url为http://192.168.1.110:8080/OTOPE/servlet/LoginInfo