php結合安卓客戶端實現(xiàn)查詢交互實例
更新時間:2015年05月05日 08:43:42 投稿:hebedich
本文給大家分享的是php結合安卓客戶端實現(xiàn)查詢交互實例,java端主要分三步來實現(xiàn):首先進行 http request.網(wǎng)絡請求相關操作,第二步,使用execute方法發(fā)送HTTP GET請求,并返回HttpResponse對象,第三步,使用getEntity方法活得返回結果。有需要的小伙伴參考下
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 防止出現(xiàn) []
$jsonstr = json_encode($getdata->result_array(), JSON_FORCE_OBJECT);
echo $jsonstr;
}
}
java 安卓端:
doAskTask = new Runnable() {
@Override
public void run() {
// TODO
// 在這里進行 http request.網(wǎng)絡請求相關操作
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方法發(fā)送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);
}
}
};
以上所述就是本文的全部內容了,希望大家能夠喜歡。
相關文章
PHP正則匹配操作簡單示例【preg_match_all應用】
這篇文章主要介紹了PHP正則匹配操作,結合簡單實例形式分析了php中preg_match_all針對HTML標簽中P元素及img src元素內容的獲取技巧,需要的朋友可以參考下2017-07-07
PHP簡單選擇排序(Simple Selection Sort)算法學習
這篇文章主要為大家詳細介紹了PHP簡單選擇排序(Simple Selection Sort)算法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-01-01
從MySQL數(shù)據(jù)庫表中取出隨機數(shù)據(jù)的代碼
這個例子是用于一個簡單的應用開發(fā)了,意思就是把現(xiàn)在表中的所有數(shù)據(jù)我們隨機讀出來一次之后再進行隨機保存到另一個表,從而達到了記錄隨機的功能2007-09-09
PHP+mysql實現(xiàn)從數(shù)據(jù)庫獲取下拉樹功能示例
這篇文章主要介紹了PHP+mysql實現(xiàn)從數(shù)據(jù)庫獲取下拉樹功能,結合實例形式分析了php+mysql數(shù)據(jù)庫查詢及select下拉框輸出查詢結果的實現(xiàn)技巧,需要的朋友可以參考下2017-01-01

