欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

Java 发出HTTP GET请求抓取网页内容,抓取网页内容,DefaultHttpC

来源: javaer 分享于  点击 7856 次 点评:125

Java 发出HTTP GET请求抓取网页内容,抓取网页内容,DefaultHttpC


DefaultHttpClient httpclient = new DefaultHttpClient();       HttpGet httpGet = new HttpGet("http://192.168.1.25:82/WebService/WebService1.asmx/Login?Staff_Name=string&Staff_Password=string");       HttpResponse response1 = httpclient.execute(httpGet);       // The underlying HTTP connection is still held by the response object        // to allow the response content to be streamed directly from the network socket.        // In order to ensure correct deallocation of system resources        // the user MUST either fully consume the response content  or abort request        // execution by calling HttpGet#releaseConnection().       try {           System.out.println(response1.getStatusLine());           HttpEntity entity1 = response1.getEntity();           // do something useful with the response body           // and ensure it is fully consumed           String strResult = EntityUtils.toString(entity1);            System.out.println(strResult);           EntityUtils.consume(entity1);       } finally {           httpGet.releaseConnection();       }
相关栏目:

用户点评