Java-urlconnection Network data collection

Source: Internet
Author: User

Connection by URL creation method

ImportJava.io.BufferedReader;ImportJava.io.ByteArrayOutputStream;ImportJava.io.InputStream;ImportJava.io.InputStreamReader;ImportJava.net.URL;Importjava.net.URLConnection; @SuppressWarnings ("All") Public classTest { Public Static voidMain (string[] args)throwsException {URL url=NewURL ("Http://192.168.0.215:8080/tsportal/web/system/userOnlineCount"); URLConnection Connection=url.openconnection (); Connection.setconnecttimeout (20000); Connection.setreadtimeout (20000); Connection.setusecaches (false); Connection.setrequestproperty ("User-agent", "mozilla/5.0 (Windows NT 6.1) applewebkit/537.11 (khtml, like Gecko) chrome/23.0.1271.64 safari/537.11"); InputStream is=Connection.getinputstream (); InputStreamReader InputStreamReader=NewInputStreamReader (IS, "Utf-8"); BufferedReader bis=NewBufferedReader (InputStreamReader); String Line=NULL; StringBuffer result=NewStringBuffer ();  while(line = Bis.readline ())! =NULL) {result.append (line);     } System.out.println (Result.tostring ()); }}

Java-urlconnection Network data collection

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.