Network Programming 01

Source: Internet
Author: User

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 ();

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.