public static String connect(String dataUrl){ String result = null; try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost("http://rs.260g.com:8090/index.php?c=user&a=login"); httpPost.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"); // 创建名/值组列表 List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("username", "******")); parameters.add(new BasicNameValuePair("password", "*****")); parameters.add(new BasicNameValuePair("rememberMe", "****")); // 创建UrlEncodedFormEntity对象 UrlEncodedFormEntity formEntiry = new UrlEncodedFormEntity(parameters); httpPost.setEntity(formEntiry); HttpResponse httpResponse = httpclient.execute(httpPost); HttpEntity entity = httpResponse.getEntity(); result = IOUtils.toString(entity.getContent()); HttpGet searchHttpGet = new HttpGet(dataUrl); searchHttpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"); httpResponse = httpclient.execute(searchHttpGet); result = IOUtils.toString(httpResponse.getEntity().getContent()); } catch (Exception e) { e.printStackTrace(); } return result; }