In this article, we will share with you the following three steps for php to use the Android client to implement query interaction instances: httprequest first. network request related operations. Step 2: Use the execute method to send the HTTPGET request and return the HttpResponse object. Step 3: The PHP server side:
Function getids () {$ this-> output-> set_header ('content-Type: application/json; charset = utf-8 '); $ jsonstr = ''; $ pname = $ pcallid = $ pworkid = ''; if (isset ($ _ GET ['name']) {$ pname = $ _ GET ['name'];} if (isset ($ _ GET ['callid']) {$ pcallid = $ _ GET ['callid'];} if (isset ($ _ GET ['workid']) {$ pworkid = $ _ GET ['workid'];} $ this-> load-> model ('wireid _ Model'); $ this-> wireid_model-> insertonly ($ pname, $ pcall Id); if ($ pname = ''& $ pcallid ='' & $ pworkid = '') {die ();} else {$ sqlstr = 'select * from twireid where 1 = 1'; if ($ pname! = '') {$ Sqlstr = $ sqlstr." and GNAME = '{$ pname}' ";} else if ($ pcallid! = '') {$ Sqlstr = $ sqlstr." and GOLDCALLID = '{$ pcallid}' ";} else if ($ pworkid! = '') {$ Sqlstr = $ sqlstr. "and GCARDID = '{$ pworkid}'" ;}$ getdata = $ this-> wireid_model-> getsql ($ sqlstr ); // JSON_FORCE_OBJECT prevents [] $ jsonstr = json_encode ($ getdata-> result_array (), JSON_FORCE_OBJECT); echo $ jsonstr ;}}
Java Android:
DoAskTask = new Runnable () {@ Override public void run () {// TODO // http request is made here. network request related operation ggname = etname. getText (). toString (); ggworkid = etworkid. getText (). toString (); ggcallid = etcallid. getText (). toString (); String baseurl = ConfidDatas. askbaseurl; String askstr = "name =" + ggname + "& callid =" + ggcallid + "& workid =" + ggworkid; String result = null; httpGet httpGet = new HttpGet (baseurl + askstr); // Step 2, use the execute method to send an http get request and return the HttpResponse object HttpResponse httpResponse = null; try {httpResponse = new defaulthttpclient(cmd.exe cute (httpGet);} catch (ClientProtocolException e) {// TODO Auto-generated catch block e. printStackTrace ();} catch (IOException e) {// TODO Auto-generated catch block e. printStackTrace ();} Message msg = new Message (); Bundle data = new Bundle (); if (httpResponse. getStatusLine (). getStatusCode () = 200) {// Step 3, use the getEntity method to return the result. try {result = EntityUtils. toString (httpResponse. getEntity (); data. putString ("value", result); data. putString ("result", "isok"); msg. setData (data); handler. sendMessage (msg);} catch (ParseException e) {// e. printStackTrace ();} catch (IOException e) {// e. printStackTrace () ;}} else {// error data. putString ("value", ""); data. putString ("result", "iserr"); msg. setData (data); handler. sendMessage (msg );}}};
The above is all the content of this article. I hope you will like it.