php結(jié)合安卓客戶端實(shí)現(xiàn)查詢交互實(shí)例
更新時(shí)間:2015年05月05日 08:43:42 投稿:hebedich
本文給大家分享的是php結(jié)合安卓客戶端實(shí)現(xiàn)查詢交互實(shí)例,java端主要分三步來實(shí)現(xiàn):首先進(jìn)行 http request.網(wǎng)絡(luò)請(qǐng)求相關(guān)操作,第二步,使用execute方法發(fā)送HTTP GET請(qǐng)求,并返回HttpResponse對(duì)象,第三步,使用getEntity方法活得返回結(jié)果。有需要的小伙伴參考下
PHP 服務(wù)器端:
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}' "; } 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 防止出現(xiàn) [] $jsonstr = json_encode($getdata->result_array(), JSON_FORCE_OBJECT); echo $jsonstr; } }
java 安卓端:
doAskTask = new Runnable() { @Override public void run() { // TODO // 在這里進(jìn)行 http request.網(wǎng)絡(luò)請(qǐng)求相關(guān)操作 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); // 第二步,使用execute方法發(fā)送HTTP GET請(qǐng)求,并返回HttpResponse對(duì)象 HttpResponse httpResponse = null; try { httpResponse = new DefaultHttpClient().execute(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) { // 第三步,使用getEntity方法活得返回結(jié)果 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 { // 錯(cuò)誤 data.putString("value", ""); data.putString("result", "iserr"); msg.setData(data); handler.sendMessage(msg); } } };
以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。
相關(guān)文章
PHP正則匹配操作簡(jiǎn)單示例【preg_match_all應(yīng)用】
這篇文章主要介紹了PHP正則匹配操作,結(jié)合簡(jiǎn)單實(shí)例形式分析了php中preg_match_all針對(duì)HTML標(biāo)簽中P元素及img src元素內(nèi)容的獲取技巧,需要的朋友可以參考下2017-07-07PHP簡(jiǎn)單選擇排序(Simple Selection Sort)算法學(xué)習(xí)
這篇文章主要為大家詳細(xì)介紹了PHP簡(jiǎn)單選擇排序(Simple Selection Sort)算法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01php獲取遠(yuǎn)程文件內(nèi)容的函數(shù)
這篇文章主要介紹了關(guān)于php獲取遠(yuǎn)程文件內(nèi)容的函數(shù)代碼,使用這個(gè)函數(shù)也可以獲取圖片2015-11-11從MySQL數(shù)據(jù)庫表中取出隨機(jī)數(shù)據(jù)的代碼
這個(gè)例子是用于一個(gè)簡(jiǎn)單的應(yīng)用開發(fā)了,意思就是把現(xiàn)在表中的所有數(shù)據(jù)我們隨機(jī)讀出來一次之后再進(jìn)行隨機(jī)保存到另一個(gè)表,從而達(dá)到了記錄隨機(jī)的功能2007-09-09PHP+mysql實(shí)現(xiàn)從數(shù)據(jù)庫獲取下拉樹功能示例
這篇文章主要介紹了PHP+mysql實(shí)現(xiàn)從數(shù)據(jù)庫獲取下拉樹功能,結(jié)合實(shí)例形式分析了php+mysql數(shù)據(jù)庫查詢及select下拉框輸出查詢結(jié)果的實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-01-01