希望能给出代码!!多谢!

解决方案 »

  1.   


     URL url=new URL(tagetURL);
     InputStream is=url.openStream();或socket方式
      以类似的方式构造出HTTP  header----------------------------------------------------------------
      String header = "GET " + httpreq + " HTTP/1.1\r\n";
            header += "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, application/x-icq, */*\r\n";
            header += "Accept-Language: zh-cn\r\n";
            header += "Accept-Encoding: gzip, deflate\r\n";
            header += "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Maxthon; .NET CLR 1.0.3705)\r\n";
            header += "Host: " + host + "\r\n";
            header += "Connection: Keep-Alive\r\n";
    --------------------------------------------------------------------------------然后:        InetAddress addr = InetAddress.getByName(host);
            Socket socket = new Socket(addr);
            InputStream is = socket.getInputStream();
            OutputStream os = socket.getOutputStream();
            os.write(sb.toString().getBytes());
            os.flush();
      

  2.   

    import java.net.*;
    import java.io.*;public class URLReader {
        public static void main(String[] args) throws Exception {
    URL yahoo = new URL("http://www.yahoo.com/");
    BufferedReader in = new BufferedReader(
    new InputStreamReader(
    yahoo.openStream())); String inputLine; while ((inputLine = in.readLine()) != null)
        System.out.println(inputLine); in.close();
        }
    }
      

  3.   

    直接使用Apache的http-client common就是了
      

  4.   

    import java.net.*;
    import java.io.*;public class URLReader {
        public static void main(String[] args) throws Exception {
    if (args.length == 0) {
    System.out.println("usage: java URLReader <a URL>");
    System.exit(0);
    } URL yahoo = new URL(args[0]);
    BufferedReader in = new BufferedReader(
    new InputStreamReader(
    yahoo.openStream())); String inputLine; while ((inputLine = in.readLine()) != null)
    System.out.println(inputLine); in.close();
        }
    }