1. http-based Network Programming
URL, URLConnection, HttpURLConnection, JarURLConnection
Uniform URL Resource Locator
Create a URL Connection:
First, declare a URL object to locate the resource address.
1. Call the openConnection method on the URL to create a connection object.
2. process the set parameters and common request attributes.
3. Use the connect method to establish the actual connection to the remote object.
4. remote objects become available. The header field and content of the remote object become accessible.
<! -- EndFragment -->
Public static void test01 (){
URL url = null;
Try {
Url = new URL ("http: // 192.168.0.12: 8080/mp3/resources. xml ");
URLConnection urlc = url. openConnection ();
Urlc. connect ();
StringBuffer sb = new StringBuffer ();
BufferedReader br =
New BufferedReader (new InputStreamReader (urlc. getInputStream ()));
String str = "";
While (str = br. readLine ())! = Null ){
Sb. append (str );
}
System. out. print (sb. toString ());
} Catch (MalformedURLException e ){
E. printStackTrace ();
} Catch (IOException e ){
E. printStackTrace ();
}
}