php结合安卓客户端实现查询交互实例
程序员文章站
2023-10-27 14:34:58
php 服务器端:
function getids()
{
$this->output->set_header('content-type...
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() { @override public 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 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方法活得返回结果 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); } } };
以上所述就是本文的全部内容了,希望大家能够喜欢。
上一篇: 对虾价格多少,主要受到季节和品种的影响
下一篇: 头晕喝什么好,这些一定要试试