i new in android,and have been trying android application using php rest api , cant find example doing this.kindly me. code in android client side
public void btnclick(view view){
textview textview = (textview)findviewbyid(r.id.textview1); httpclient httpclient = new defaulthttpclient(); httpget httpget = new httpget("http://localhost/project/php-api-template/demo/hello.json"); httpcontext localcontext = new basichttpcontext(); httpget.setheader("accept", "application/json"); httpget.setheader("content-type", "application/json"); toast.maketext(getapplicationcontext(), "this toast message!!! =)", toast.length_long).show(); try { httpresponse response = httpclient.execute(httpget,localcontext); string jsonresult = inputstreamtostring(response.getentity().getcontent()).tostring(); jsonobject object = new jsonobject(jsonresult); string name = object.getstring("data"); textview.settext(name); } catch (jsonexception e) { e.printstacktrace(); } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } }
Comments
Post a Comment