java 访问http

来源:互联网 发布:淘宝怎么运营 编辑:程序博客网 时间:2024/06/11 08:11
     public static String getURLContent(String urlStr) {                              /** 网络的url地址 */                    URL url = null;                             /** http连接 */                HttpURLConnection httpConn = null;                            /**//** 输入流 */               BufferedReader in = null;               StringBuffer sb = new StringBuffer();               try{                  url = new URL(urlStr);                  in = new BufferedReader( new InputStreamReader(url.openStream(),"UTF-8") );                String str = null;                 while((str = in.readLine()) != null) {                  sb.append( str );                         }                     } catch (Exception ex) {                   } finally{                     try{                               if(in!=null) {                     in.close();                             }                         }catch(IOException ex) {                          }                     }                     String result =sb.toString();                     return result;                    }    
0 0