php 與java安卓用戶端的查詢互動

來源:互聯網
上載者:User
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);}}};

  

以上就介紹了php 與java安卓用戶端的查詢互動,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.