while(true){
  int tmp=input.read();
  if(tmp==-1) break;
  System.out.write(tmp);
}

解决方案 »

  1.   

    不用试这里有个http://www.innovation.ch/java/HTTPClient/
      

  2.   

    to skyyoung:
      我正是用这个的,可是问题还是存在.看来要用Socket编过和WEB服务器通讯的人才能真正了解了.
      

  3.   

    以下是我实现的代码.
    import HTTPClient.*;
    ......
    ....
    ..
      void jButton3_actionPerformed(ActionEvent e) {
        try{
          String url ="www.netshi.net";
          String urlFile = "/789net/bbs.cgi";
          //String url ="club.163.com";
          //String urlFile = "/index.html";
          conn = new HTTPConnection(url);
          CookieModule.setCookiePolicyHandler (null);
          rsp = conn.Get(urlFile);
          if (rsp.getStatusCode() >= 300){
                System.err.println("Received Error: "+rsp.getReasonLine());
       System.err.println(rsp.getText());
          } else {
           input = new BufferedInputStream(rsp.getInputStream ());
          }
          conn = new HTTPConnection(url);
          rsp = conn.Get(urlFile);
          if (rsp.getStatusCode() >= 300){
           System.err.println("Received Error: "+rsp.getReasonLine());
          System.err.println(rsp.getText());
          else {
            input = new BufferedInputStream(rsp.getInputStream ());
          }
        } catch(Exception ex){
          ex.printStackTrace();
        }
     } // end of jButton3_actionPerformed另: to haichuang:
       这样一个一个Byte读一个流觉得很难受.
       有没有更好方法?
      

  4.   

    问题已经解决了。
    现在可以得出结论:
      在HTTP协议中,当用户Get一个需要Cookie的文件时,Server端会返回一个带Set Cookie头的回应。这样完成了第一个连接。如果浏览器支持 Cookie,在检测到这个信息后会查找本地有否该cookie,如果有则使用该cookie再次向server请求,如果没有则设置cookie,然后用该cookie再次请求。这是第二个连接。也许要求太高,不过我对CSDN的确是越来越失望了。
    :(