HTTP-based communication
package com.example.httpgetdemo;public class mainactivity extends activity {@ Overrideprotected void oncreate (bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.activity_main); Findviewbyid (R.id.button1). SetOnClickListener (New view.onclicklistener () {@Overridepublic void onclick (view v) {new Asynctask<string, void, void> () {@Overrideprotected void doinbackground (String ... params) {try {url url = new url (Params[0]); Urlconnection connection = url.openconnection ();inputstream inputstream = Connection.getinputstream (); Inputstreamreader isr = new inputstreamreader (InputStream, "Utf-8"); Bufferedreader br = new bufferedreader (ISR); string line;while ((Line = br.readline ()) != null) {system.out.println (line );} BR.close (); Isr.close (); Inputstream.close ();} catch (malformedurlexception e) {e.printstacktrace ();} catch (ioexception e) {e.printstacktrace ();} Return null;}}. Execute ("http://fanyi.youdao.com/openapi.do?keyfrom=httpgetdemo1&key=1659546208&type=data&doctype= Json&version=1.1&q=good ");}});}
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/5B/33/wKioL1UCSS7C34HJAAFI1Q5h1p8373.jpg "title=" Qq20150313101421.jpg "alt=" Wkiol1ucss7c34hjaafi1q5h1p8373.jpg "/>
This article is from "Avatar" blog, please make sure to keep this source http://shamrock.blog.51cto.com/2079212/1619980
Android Learning notes-HTTP-based communication technology