<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    vickzhu

      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      151 隨筆 :: 0 文章 :: 34 評(píng)論 :: 0 Trackbacks
    以下都是實(shí)戰(zhàn)經(jīng)驗(yàn):
    1、Socket讀取
          String strServer=http://www.google.cn;//這里同樣可以用ip來(lái)訪問(wèn):203.208.35.100
          String strPage="/language_tools?hl=zh-CN";
          try { 
               String hostname = strServer; 
               int port = 80; 
               InetAddress addr = InetAddress.getByName(hostname); 
               Socket socket = new Socket(addr, port);
               BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8")); 
               wr.write("GET " + strPage + " HTTP/1.0\r\n"); 
               wr.write("HOST:" + strServer + "\r\n"); 
               wr.write("\r\n"); 
               wr.flush();
               BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));
               String line; 
               while ((line = rd.readLine()) != null) { 
                    System.out.println(line); 
               }
               wr.close(); 
               rd.close(); 
          } catch (Exception e) { 
               System.out.println(e.toString()); 
          }
    2、HttpClient方式
          HttpClient client=new HttpClient();
          GetMethod method=new GetMethod("       int status=client.executeMethod(method);
          if(status==HttpStatus.SC_OK){
           //讀取內(nèi)容
           byte[] responseBody = method.getResponseBody();
           //處理內(nèi)容
           System.out.println(new String(responseBody));
           System.out.println("文件名稱:"+method.getPath());
            }
    3、HttpURLConnection方式
          URL url = new URL("這里是你要連接的地址");
          HttpURLConnection conn = (HttpURLConnection)url.openConnection();
          conn.setDoOutput(true);//是否可用于輸出(輸出參數(shù)),默認(rèn)為fasle。另:setDoInput()為是否可用于輸入,默認(rèn)為true
          String parameters = "name=admin&password=123456";//這里是要傳遞的參數(shù)
          OutputStream os = conn.getOutputStream();
          os.write(parameters.getBytes("utf-8"));
          os.flush();
          os.close();
          System.out.println("返回狀態(tài)碼:"+conn.getResponseCode());
          System.out.println("返回消息:"+conn.getResponseMessage());
          InputStream is = conn.getInputStream();
          BufferedReader br = new BufferedReader(new InputStreamReader(is,"utf-8"));
          String line = null;
          while((line=br.readLine())!=null){
           System.out.println(line);
          }
        //  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();;
        //  DocumentBuilder db = dbf.newDocumentBuilder();
        //  Document doc = db.parse(is);
    如果誰(shuí)還有更多的方式分享,請(qǐng)留言!

    評(píng)論

    # re: java 讀取頁(yè)面源碼 的多種方式[未登錄](méi) 2008-11-24 20:39 fisher
    GetMethod method=new GetMethod("http://www.baidu.com/");

    GetMethod ?

    這個(gè)東西哪來(lái)的?  回復(fù)  更多評(píng)論
      

    # re: java 讀取頁(yè)面源碼 的多種方式 2008-11-25 09:03 vickzhu
    你好HttpClient和GetMethod都是來(lái)自apache的包  回復(fù)  更多評(píng)論
      


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 国产免费爽爽视频免费可以看| 亚洲国产成人乱码精品女人久久久不卡| 亚洲三级中文字幕| 日本高清免费不卡在线| 国产亚洲精品福利在线无卡一| 成人影片一区免费观看| 亚洲人成人77777在线播放| 国产一区二区三区免费视频| 日本不卡免费新一区二区三区| 国产精品国产亚洲精品看不卡| av无码国产在线看免费网站| 美女视频黄频a免费| 久久久久亚洲AV成人无码网站| 成人免费视频一区二区三区| 精品多毛少妇人妻AV免费久久| 亚洲图片中文字幕| 久久亚洲中文字幕精品一区四| 歪歪漫画在线观看官网免费阅读| 视频免费1区二区三区| 亚洲午夜久久久久久尤物| 亚洲日本韩国在线| 手机在线免费视频| 嫩草在线视频www免费观看| 久久亚洲AV成人无码国产电影 | 亚洲乱亚洲乱少妇无码| 在免费jizzjizz在线播| 国产vA免费精品高清在线观看| 亚洲最大黄色网址| 亚洲中文字幕在线乱码| 四虎永久在线精品免费影视 | 亚洲精品中文字幕| 亚洲国产高清人在线| 免费一级毛片在线观看| 久久精品a一国产成人免费网站| APP在线免费观看视频| 手机永久免费的AV在线电影网| 亚洲一久久久久久久久| 亚洲精品中文字幕无码AV| 国产∨亚洲V天堂无码久久久| 亚洲国产主播精品极品网红| 精品剧情v国产在免费线观看|