/*** The httpclientPost Request Method ** @ param username * @ param password * @ return null indicates that the obtained path is incorrect, text returns the requested data */public static String httpclientPost (String username, String password) {try {// 1. open a browser: HttpClient client = new DefaultHttpClient (); // 2. input address String path = "http: // 172.22.64.156: 8080/0001 AndroidWebService/LoginServlet"; HttpPost post = new HttpPost (); // specify the List of submitted data entities
Parameters = new ArrayList
(); Parameters. add (new BasicNameValuePair ("username", username); parameters. add (new BasicNameValuePair ("password", password); post. setEntity (new UrlEncodedFormEntity (parameters, "UTF-8"); // 3, press ENTER HttpResponse response = client.exe cute (post); // get The Returned code int code = response. getStatusLine (). getStatusCode (); if (code = 200) {// obtain the returned information InputStream is = response. getEntity (). getContent (); String text = StreamUtil. readStream (is); return text;} else {return null ;}} catch (Exception e) {e. printStackTrace (); return null ;}}