php 与java安卓客户端的查询交互

王朝学院·作者佚名  2016-05-25
窄屏简体版  字體: 小  |  中  |  大  |  超大  

php 与java安卓客户端的查询交互PHP 服务器端:

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 防止出现 [] $jsonstr = json_encode($getdata->result_array(), JSON_FORCE_OBJECT); echo $jsonstr; } }

java 安卓端:

doAskTask = new Runnable() {@Overridepublic void run() {// TODO// 在这里进行 http request.网络请求相关操作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方法发送HTTP GET请求,并返回HttPResponse对象HttpResponse httpResponse = null;try {httpResponse = new DefaultHttpClient().execute(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) {// 第三步,使用getEntity方法活得返回结果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 { // 错误data.putString("value", "");data.putString("result", "iserr");msg.setData(data);handler.sendMessage(msg);}}};

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航