[Java] Java 发出HTTP GET请求抓取网页内容 →→→→→进入此内容的聊天室

来自 , 2019-08-31, 写在 Java, 查看 155 次.
URL http://www.code666.cn/view/3e3aa687
  1. DefaultHttpClient httpclient = new DefaultHttpClient();
  2.        HttpGet httpGet = new HttpGet("http://192.168.1.25:82/WebService/WebService1.asmx/Login?Staff_Name=string&Staff_Password=string");
  3.  
  4.        HttpResponse response1 = httpclient.execute(httpGet);
  5.  
  6.        // The underlying HTTP connection is still held by the response object
  7.        // to allow the response content to be streamed directly from the network socket.
  8.        // In order to ensure correct deallocation of system resources
  9.        // the user MUST either fully consume the response content  or abort request
  10.        // execution by calling HttpGet#releaseConnection().
  11.  
  12.        try {
  13.            System.out.println(response1.getStatusLine());
  14.            HttpEntity entity1 = response1.getEntity();
  15.            // do something useful with the response body
  16.            // and ensure it is fully consumed
  17.            String strResult = EntityUtils.toString(entity1);
  18.            System.out.println(strResult);
  19.            EntityUtils.consume(entity1);
  20.            
  21.        } finally {
  22.            httpGet.releaseConnection();
  23.        }
  24. //java/6862

回复 "Java 发出HTTP GET请求抓取网页内容"

这儿你可以回复上面这条便签

captcha