国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php結合安卓客戶端實現查詢交互實例

2024-05-04 23:34:52
字體:
來源:轉載
供稿:網友

本文給大家分享的是php結合安卓客戶端實現查詢交互實例,java端主要分三步來實現:首先進行 http request.網絡請求相關操作,第二步,使用execute方法發送HTTP GET請求,并返回HttpResponse對象,第三步,使用getEntity方法活得返回結果。有需要的小伙伴參考下

PHP 服務器端:

 

 
  1. function getids() 
  2. $this->output->set_header('Content-Type: application/json; charset=utf-8'); 
  3. $jsonstr = ''
  4. $pname = $pcallid = $pworkid = ''
  5.  
  6. if (isset($_GET['name'])) { 
  7. $pname = $_GET['name']; 
  8.  
  9. if (isset($_GET['callid'])) { 
  10. $pcallid = $_GET['callid']; 
  11.  
  12. if (isset($_GET['workid'])) { 
  13. $pworkid = $_GET['workid']; 
  14.  
  15. $this->load->model('wireid_model'); 
  16.  
  17. $this->wireid_model->insertonly($pname$pcallid); 
  18.  
  19. if ($pname == '' && $pcallid == '' && $pworkid == '') { 
  20. die(); 
  21. else { 
  22. $sqlstr = 'select * from twireid where 1=1 '
  23. if ($pname != '') { 
  24. $sqlstr = $sqlstr . " and GNAME='{$pname}' "
  25. else 
  26. if ($pcallid != '') { 
  27. $sqlstr = $sqlstr . " and GOLDCALLID='{$pcallid}' "
  28. else 
  29. if ($pworkid != '') { 
  30. $sqlstr = $sqlstr . " and GCARDID='{$pworkid}' "
  31. $getdata = $this->wireid_model->getsql($sqlstr); 
  32. // JSON_FORCE_OBJECT 防止出現 [] 
  33. $jsonstr = json_encode($getdata->result_array(), JSON_FORCE_OBJECT); 
  34. echo $jsonstr

java 安卓端:

 

 
  1. doAskTask = new Runnable() { 
  2. @Override 
  3. public void run() { 
  4. // TODO 
  5. // 在這里進行 http request.網絡請求相關操作 
  6. ggname = etname.getText().toString(); 
  7. ggworkid = etworkid.getText().toString(); 
  8. ggcallid = etcallid.getText().toString(); 
  9.  
  10. String baseurl = ConfidDatas.askbaseurl; 
  11. String askstr = "name=" + ggname + "&callid=" + ggcallid 
  12. "&workid=" + ggworkid; 
  13. String result = null
  14.  
  15. HttpGet httpGet = new HttpGet(baseurl + askstr); 
  16. // 第二步,使用execute方法發送HTTP GET請求,并返回HttpResponse對象 
  17. HttpResponse httpResponse = null
  18.  
  19. try { 
  20. httpResponse = new DefaultHttpClient().execute(httpGet); 
  21. catch (ClientProtocolException e) { 
  22. // TODO Auto-generated catch block 
  23. e.printStackTrace(); 
  24. catch (IOException e) { 
  25. // TODO Auto-generated catch block 
  26. e.printStackTrace(); 
  27.  
  28. Message msg = new Message(); 
  29. Bundle data = new Bundle(); 
  30.  
  31. if (httpResponse.getStatusLine().getStatusCode() == 200) { 
  32. // 第三步,使用getEntity方法活得返回結果 
  33. try { 
  34. result = EntityUtils.toString(httpResponse.getEntity()); 
  35. data.putString("value", result); 
  36. data.putString("result""isok"); 
  37. msg.setData(data); 
  38. handler.sendMessage(msg); 
  39. catch (ParseException e) { 
  40. // e.printStackTrace(); 
  41. catch (IOException e) { 
  42. // e.printStackTrace(); 
  43. else { // 錯誤 
  44. data.putString("value"""); 
  45. data.putString("result""iserr"); 
  46. msg.setData(data); 
  47. handler.sendMessage(msg); 
  48. }; 

以上所述就是本文的全部內容了,希望大家能夠喜歡。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金沙县| 榆树市| 大庆市| 南陵县| 肥城市| 河西区| 壤塘县| 吴桥县| 团风县| 庆城县| 克什克腾旗| 姚安县| 日土县| 新疆| 惠水县| 元阳县| 凤庆县| 崇左市| 江山市| 思南县| 慈利县| 临江市| 庐江县| 吴堡县| 夹江县| 北安市| 清水县| 潼关县| 西丰县| 江西省| 连云港市| 肥城市| 邢台县| 大兴区| 鲜城| 中卫市| 新宁县| 五峰| 南乐县| 年辖:市辖区| 衡水市|