2014/05/30

Android 透過GET傳送至PHP


PHP:
<?php
 //Unicode
 header("Content-Type:text/html; charset=utf-8");
 
 $a =  $_GET['a'];
 $b = $_GET['b'];
 ...
 

?>


Android

  HttpClient httpclient = new DefaultHttpClient();
  HttpGet get = new HttpGet("Your url");
  try {
   HttpResponse response = httpclient.execute(get);
   HttpEntity entity = response.getEntity();
   return EntityUtils.toString(entity, "UTF-8");
  } catch (ClientProtocolException e) {
   Log.d("error", e.getMessage());
   e.printStackTrace();
  } catch (IOException e) {
   Log.d("error", e.getMessage());
   e.printStackTrace();
  }