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}' ;} elseif ($pcallid != '') {$sqlstr = $sqlstr . and goldcallid='{$pcallid}' ;} elseif ($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);}} };
以上所述就是本文的全部内容了,希望大家能够喜欢。
