Package com.newegg.frontservice.test;
Import java.net.URLConnection;
Import java.net.HttpURLConnection;
Import java.net.JarURLConnection;
Import Java.net.URL;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Import Java.io.InputStream;
Import Java.io.BufferedReader;
Import Java.io.InputStreamReader;
public class Urlconnectiontest {public static void main (String []args) {try{/* * Method One
* URL url = new URL ("http://www.sina.com.cn");
URLConnection Urlcon = Url.openconnection ();
InputStream is = Urlcon.getinputstream ();
*/* * Method two * * URL url = new URL ("http://www.yhfund.com.cn");
HttpURLConnection Urlcon = (httpurlconnection) url.openconnection ();
InputStream is = Urlcon.getinputstream (); */* * method three * URL url = new URL("http://www.yhfund.com.cn");
InputStream is = Url.openstream ();
*/Long BeginTime = System.currenttimemillis ();
URL url = new URL ("AAA");
HttpURLConnection Urlcon = (httpurlconnection) url.openconnection (); Urlcon.connect ();
Get connection InputStream is = Urlcon.getinputstream ();
BufferedReader buffer = new BufferedReader (new InputStreamReader (IS));
StringBuffer bs = new StringBuffer ();
String L = null;
while ((L=buffer.readline ())!=null) {bs.append (L). Append ("/n");
} System.out.println (Bs.tostring ());
System.out.println ("Content-encode:" +urlcon.getcontentencoding ());
System.out.println ("Content-length:" +urlcon.getcontentlength ());
System.out.println ("Content-type:" +urlcon.getcontenttype ());
System.out.println ("Date:" +urlcon.getdate ());
SYSTEM.OUT.PRINTLN ("Total Execution Time:" + (System.currenttimemillis ()-begintime) + "MS");
}catch (IOException e) {System.out.println (e); }
}
}