Android reads network data using the Get mode of HTTP

Source: Internet
Author: User

In order to prevent the UI thread from being unresponsive in Android, network traffic generally uses Asynctask (the lightweight asynchronous Operation class in Android), which is no longer elaborated in this article.

Body Start

New Asynctask<string,void,void> () {@Override protected Void doinbackground (String ... params) {                 try {URL url = new URL (params[0]);                URLConnection connection = Url.openconnection ();                 InputStream is = Connection.getinputstream ();                 InputStreamReader ISR = new InputStreamReader (IS, "utf-8");                 BufferedReader br = new BufferedReader (ISR);                 String Line;                 while (line = Br.readline ())! = null) {System.out.println (line);                 } br.close ();                 Isr.close ();             Is.close ();             } catch (Malformedurlexception e) {e.printstacktrace ();             } catch (IOException e) {e.printstacktrace ();         } return null; }}.execute ("Http://fanyi.youdao.com/openapi.do?keyfrom=jin123d1&key=" own Key "&type=data&doctype= json&Amp;version=1.1&q=good "); 

Here used Youdao Translation API (oneself can go to Youdao translation Official website application)

After the completion of the implementation can be in the logcat to hear the Youdao translation of Chinese content

Android reads network data using the Get mode of HTTP

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.