⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpclient.java

📁 JAVA分布式程序学习的课件(全英文)
💻 JAVA
字号:
// MyStreamSocket is a Java class presented in Chapter 4.
// import MyStreamSocket;
import java.net.*;
import java.io.*;

public class HTTPClient {

// An application which communicates with a HTTP
// server to retrieve the text contents of a web page.
// These command line arguments are expected, in order: 
//    <host name of the HTTP server>
//    <port number of the HTTP server>
//    <full path to a web document on the server host>

   public static void main(String[] args) {
      if (args.length != 3)
         System.out.println
            ("This program requires 3 command line arguments");
      else {
         try {
  		      InetAddress host = 
                InetAddress.getByName(args[0]);
  		      int port = Integer.parseInt(args[1]);
            String fileName = args[2].trim();
            String request = 
               "GET " + fileName + " HTTP/1.0\n\n";
         	MyStreamSocket mySocket = 
              new MyStreamSocket(host, port);                             
            /**/  System.out.println("Connection made");
            mySocket.sendMessage(request);
	         // now receive the response from the HTTP server
            String response;         
            response = mySocket.receiveMessage();
            // read and display one line at a time
            while (response != null) {
              System.out.println(response);
              response = mySocket.receiveMessage();
            }
         } // end try
         catch (Exception ex) {
            System.out.println("ERROR : " + ex) ;
	         ex.printStackTrace(System.out);
	      }  // end catch
      }// end else
   }// end main 
} //end class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -