Several articles about "Glance Website"

xiaoxiao2021-03-06  19

Online related article: Java / JSP Learning Series 11 (simple "scratch web page" code)

Take the information you need from HTML --------------------------------------- -------------------------------------------------- ------------------------------ Through Java.Net.Socket Class Clapline Content Original Link: http: // blog. 9cbs.net/cqq/archive/2004/09/24/115664.aspx

** File Name: FirstSocket.java Description: java.net.Socket class by accessing a Web page, and returns the result of: Ci Qin-cqq1978@yeah.net Reference: http: //java.sun.com ** /

Import java.io. *; import java.net. *;

Public class firstsocket {public static void main (string args []) {// judgment parameter is two, the correct usage is the firstSocket website page IF (args.length! = 2) {system.out.println ("usage: FirstSocket Host Page / R / NEXAMPLE: FIRSTSOCKET www.google.com / "); system.exit (0);} string strserver = args [0]; // get the first parameter string strPage = args [1]; / / Acquisition second parameters

try {String hostname = strServer; int port = 80; InetAddress addr = InetAddress.getByName (hostname); Socket socket = new Socket (addr, port); // send a command to establish a Socket // BufferedWriter wr = new BufferedWriter (new OutputStreamWriter (Socket.getOutputStream (), "UTF8")); Wr.Write ("get" strpage "http / 1.0 / r / n"); Wr.Write ("Host:" strser "/ r / n "); Wr.write (" / r / n "); wr.flush (); // Receive returned result bufferedreader rd = new bufferedreader (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 ());}}}

转载请注明原文地址:https://www.9cbs.com/read-44458.html

New Post(0)