Read stream data via Rul This bar applies to webservice-restful execution interface __web

Source: Internet
Author: User
Tags stringbuffer
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); }
    }
 
}

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.