Get data through GET request
Public static string sendgetrequest (string endpoint, <br/> string requestparameters) {<br/> log. I ("sendgetrequest", endpoint); <br/> string result = NULL; <br/> If (endpoint. startswith ("http ://")) {<br/> // send a GET request to the servlet <br/> try {<br/> // construct data <br/> stringbuffer DATA = new stringbuffer (); <br/> // send data <br/> string urlstr = endpoint; <br/> If (requestparameters! = NULL & requestparameters. Length ()> 0) {<br/> urlstr + = "? "+ Requestparameters; <br/>}< br/> log. I ("urlstr", urlstr); <br/> url = new URL (urlstr); <br/> urlconnection conn = URL. openconnection (); <br/> // get the response <br/> bufferedreader RD = new bufferedreader (New inputstreamreader (<br/> Conn. getinputstream (); <br/> stringbuffer sb = new stringbuffer (); <br/> string line; <br/> while (line = RD. readline ())! = NULL) {<br/> Sb. append (line); <br/>}< br/> Rd. close (); <br/> result = sb. tostring (); <br/>}catch (exception e) {<br/> E. printstacktrace (); <br/>}< br/> log. I ("sendgetrequest", result); <br/> return result; <br/>}< br/> for example, by specifying the image of a URL, obtain the image data and convert it to the supported image format of Android. The Code is as follows: <br/> // display images on the Network <br/> Public static bitmap returnbitmap (string URL) {<br/> log. I ("returnbitmap", "url =" + URL); <br/> URL myfileurl = NULL; <br/> Bitmap bitmap = NULL; <br/> try {<br/> myfileurl = new URL (URL); <br/>} catch (malformedurlexception e) {<br/> E. printstacktrace (); <br/>}< br/> try {<br/> httpurlconnection conn = (httpurlconnection) myfileurl <br/>. openconnection (); <br/> Conn. setdoinput (true); <br/> Conn. connect (); <br/> inputstream is = Conn. getinputstream (); <br/> bitmap = bitmapfactory. decodestream (is); <br/> is. close (); <br/>}catch (ioexception e) {<br/> E. printstacktrace (); <br/>}< br/> return bitmap; <br/>}