Get method Instance:
String url= "Http://202.194.14.215/iactivity/mobile/msg.php?act=1"; String tixingfanhuizhi=null;defaulthttpclient client=new defaulthttpclient ();//New Clienthttpget get=new HttpGet (URL) ; New Httpgethttpresponse Response=null;get.setheader ("Cookie", GetCookie ());//setcookie, sometimes you may not be able to use response= Client.execute (get); Tixingfanhuizhi = Entityutils.tostring (Response.getentity (), "UTF-8");D ocument Doc=jsoup.parse (Tixingfanhuizhi);//Generate a document file with a string return value, and then you can parse the HTML file with Jsoup elements pinglun=doc.select ("div"); int a= Pinglun.size ();
Post Method Instance
Defaulthttpclient httpclient = new Defaulthttpclient ();//create httpclientlist<namevaluepair> params = new ArrayList <NameValuePair> ();p Arams.add (New Basicnamevaluepair ("User", username));p arams.add (New Basicnamevaluepair (" Key ", key)); urlencodedformentity entity = null;try {entity = new urlencodedformentity (params, "UTF-8"); HttpPost HttpPost = new HttpPost (URL); httppost.setentity (entity); Using the Post method, the inside place parameter try {response = Httpclient.execute (HttpPost);//Get Httpresponseheader Header = Response.getfirstheader ("Set-cookie"); if (header = null) {HttpCookie = Header.getvalue ();} try {Fanhuishuzhi = entityutils.tostring (Response.getentity (), HTTP. UTF_8); Get the contents of code = Integer.parseint (Fanhuishuzhi);//Convert to data value} catch (ParseException e) {//TODO auto-generated catch Blocke.printstacktrace (); Toast.maketext (Getapplicationcontext (), Getresources (). getString (R.string.login_no), Toast.length_short). Show (); Dialog.dismiss ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktraCE (); Toast.maketext (Getapplicationcontext (), Getresources (). getString (R.string.login_no), Toast.length_short). Show (); Dialog.dismiss ();}} catch (Clientprotocolexception e) {//TODO auto-generated catch Blocke.printstacktrace (); Toast.maketext (Getapplicationcontext (), Getresources (). getString (R.string.login_no), Toast.length_short). Show (); Dialog.dismiss ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}} catch (Unsupportedencodingexception E1) {//TODO auto-generated catch Blocke1.printstacktrace ();}
Network Programming (i)