.假如是PHP做的效劳端,而咱们要用android去访咨询,如何办?所以能够用REST,但也能够用点笨的办法,比方能够让PHP的效劳端前往JSON或XML数据,而Android端那么能够用APACHE的client去访咨询。上面是一个例子,假定数据表中users表有如下字段(mysql):idusers,UserName,FullName加点数据,而后在效劳端树破一个据,如下:webservice1.php,感化是直截了当前往效劳端数据库的数
$post);16}17}18/*json格局*/19if($format=='json'){20header('Content-type:application/json');21echojson_encode(array('posts'=>$posts));22}23else{24header('Content-type:text/xml');25echo'';26foreach($postsas$index=>$post){27if(is_array($post)){28foreach($postas$key=>$value){29echo'<',$key,'>';30if(is_array($value)){31foreach($valueas$tag=>$val){32echo'<',$tag,'>',htmlentities($val),'',$tag,'>';33}34}35echo'',$key,'>';36}37}38}39echo'';40}41}42>434445那么能够把数据表输入为JSON或许XML格局了,客户真个Android挪用:try{12ParamsParams=newBasicParams();ConnectionParams.setConnectionTimeout(Params,3TIMEOUT_MILLISEC);4ConnectionParams.setSoTimeout(Params,TIMEOUT_MILLISEC);56Paramsp=newBasicParams();p.setParameter("user","1");7Clientclient=newStringurl=DefaultClient(p);8910"://10.0.2.2:8082/myphp/phpWebservice/webservice1.phpuser=1&format=json";Postpost=newtry{Post(url);111Log.i(getClass().getSimpleName(),"sendtask-start");ListnameValuePairs=newArrayList(2);21nameValuePairs.add(newBasicNameValuePair("user","1"));post.setEntity(newUrlEncodedFormEntity(nameValuePairs));314151ResponseHand...