php結合安卓用戶端實現查詢互動執行個體_PHP教程

來源:互聯網
上載者:User

php結合安卓用戶端實現查詢互動執行個體


  本文給大家分享的是php結合安卓用戶端實現查詢互動執行個體,java端主要分三步來實現:首先進行 http request.網路請求相關操作,第二步,使用execute方法發送HTTP GET請求,並返回HttpResponse對象,第三步,使用getEntity方法活得返回結果。有需要的小夥伴參考下

  PHP 伺服器端:

  ?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

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 安卓端:

  ?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

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);

}

}

};

  以上所述就是本文的全部內容了,希望大家能夠喜歡。

http://www.bkjia.com/PHPjc/994738.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/994738.htmlTechArticlephp結合安卓用戶端實現查詢互動執行個體 本文給大家分享的是php結合安卓用戶端實現查詢互動執行個體,java端主要分三步來實現:首先進行 http r...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.