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 HTTPG
In this article, we will share with you the following three steps for php to use the android client to implement query interaction instances: first, http request. network request related operations. Step 2: Use the execute method to send HTTP G
PHP server:
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, $ pcallid); if ( $ Pname = ''& $ pcallid ='' & $ pworkid = '') {die ();} else {$ sqlstr = 'select * from twireid where 1 = 1'; if ($ pname! = '') {$ Sqlstr = $ sqlstr." and GNAME = '{$ pname}' ";} elseif ($ pcallid! = '') {$ Sqlstr = $ sqlstr." and GOLDCALLID = '{$ pcallid}' ";} elseif ($ 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 () {@ Overridepublic 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 blocke. printStackTrace ();} catch (IOException e) {// TODO Auto-generated catch blocke. 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.