title: sending HTTP request to PHP web server by using JSON, in ANDROID
body: <p>I hope all are doing well.
  I am trying to add web services to am Android application, for this I have created PHP server. request and response is in JSON formate. and request type is "post"
  this is my request formate:</p>
  
  <pre><code>{"method_name":"checkLogin","body":   {"username":"someone@some.com","password":"password","device_type":"android","lat":"","long":""}}
  </code></pre>
  
  <p>expected Response:</p>
  
  <pre><code>[{"status":"1","message":"Login successfully","data":{"id":"xx","username":"someone@some.com","first_name":"xxx","last_name":"yyy","gender":"xxx","relationship":"xxxx","birthdate":"xxxx","hometown":"","major":null,"class":null,"house":null,"device_type":"iphone","current_location_lat":"0.0","current_location_lon":"0.0","profile_image":"no_male_user.png","is_login":"1","created":"2012","status":"1","tag":[{"id":"x","tag_name":"xxxx"},{"id":"x","tag_name":"xxx xxx"}]}}]
  </code></pre>
  
  <p>my android code:</p>
  
  <pre><code>userName = userNameField.getText().toString();
  passWord = passWordField.getText().toString();
  
  try {
  JSONObject json = new JSONObject();
  json.put("username", userName);
  json.put("password", passWord);
  json.put("device_type", "Android");
  json.put("lat", "0.0");
  json.put("long", "0.0");
  
  JSONObject json1 = new JSONObject();
  json1.put("method_name", "checkLogin");
  json1.putOpt("body", json);
  
  HttpParams httpParams = new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(httpParams,
          TIMEOUT_MILLISEC);
  HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
  HttpClient client = new DefaultHttpClient(httpParams);
  
  HttpPost request = new HttpPost(URL);
  request.setEntity(new StringEntity(json1.toString()));
  ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler();
  String response = client.execute(request, responseHandler);
  
  Toast.makeText(this, response, Toast.LENGTH_LONG).show();
  
  } catch (ClientProtocolException e) {
  e.printStackTrace();
  } catch (IOException e) {
  e.printStackTrace();
  } catch (Throwable t) {
  Toast.makeText(this, "Request failed: " + t.toString(),
          Toast.LENGTH_LONG).show();
  }
  } 
  </code></pre>
  
  <p>main.php</p>
  
  <pre><code>&lt;?php
  require_once('configure.php');
  require_once('db.php');
  require_once("request.php");
  require_once("error_msg.php");
  require_once("./includes/JSON.php");
  
  $json = $_POST['json'];
  
  $objRequest = new Request($json);
  $rows = $objRequest -&gt; main();
  echo $rows;
  ?&gt;
  </code></pre>
  
  <p>request.php</p>
  
  <pre><code>&lt;?php
  require_once("./includes/JSON.php");
  require_once("db.php");
  require_once('SimpleImage.php');
  class Request
  {
  function __construct($json)
  {
      $this -&gt; array1 = @json_decode(stripcslashes(trim($json)));
  }
  function main()
  {
      $objDb = new DB();
      $conn = $objDb -&gt; getConnection();
  
      if(!$conn)
          return Error :: $DB_CONN_ERROR." ".$DB_CONN_ERROR_DESC;
      else
      {
          if($this -&gt; array1 -&gt; method_name == 'checkLogin')
              return $this -&gt; getLoginFlag($this -&gt; array1 -&gt; body);
      }
  }
  // For Login Start
  function getLoginFlag($body)
  {
      $username = trim($body -&gt; username);
      $password = ($body -&gt; password);
      $device_type = trim($body -&gt; device_type);
  
      $this -&gt; rs_login = DB :: selectLoginRecord($body);
      $arr_resp = array();
      $retArray = array();
      $tagListArray = array();
      if(mysql_num_rows($this -&gt; rs_login) &gt; 0)
      {
          while($rows = mysql_fetch_array($this -&gt; rs_login))
          {
                  $arr_resp = array("id"=&gt; $rows['id'],"username"=&gt; $rows['username'],"first_name"=&gt; ucfirst($rows['first_name']),"last_name"=&gt;ucfirst($rows['last_name']),"gender"=&gt;$rows['gender'],"relationship"=&gt;$rows['relationship'],"birthdate"=&gt;date('M d, Y', strtotime($rows['birthdate'])),"hometown"=&gt;$rows['hometown'],"major"=&gt;$rows['major'],"class"=&gt;$rows['class'],"house"=&gt;$rows['house'],"device_type"=&gt;$rows['device_type'],"current_location_lat"=&gt;$rows['current_location_lat'],"current_location_lon"=&gt;$rows['current_location_lon'],"profile_image"=&gt;$rows['profile_image'],"is_login"=&gt;$rows['is_login'],"created"=&gt;date('Y', strtotime($rows['created'])),"status"=&gt;$rows['status']);   
          }
          $this -&gt; rs_tag_list = DB :: selectTagList($arr_resp['id']);
          if(mysql_num_rows($this -&gt; rs_tag_list) &gt; 0)
          {   
              while($rows = mysql_fetch_array($this -&gt; rs_tag_list))
              {
                  $tagListArray['tag'][]= array("id"=&gt; $rows['id'],"tag_name"=&gt; $rows['tag_name']);   
              }
          }
  
          $finalArray = array_merge($arr_resp,$tagListArray);
          $retArray[] = array("status"  =&gt; "1","message" =&gt; "Login successfully","data" =&gt; $finalArray);
      }
      else
      {
          $retArray[] = array("status" =&gt; "0","message" =&gt; "The username or password you entered is incorrect");  
      }
  
      return json_encode($retArray);
  }
  // End Login
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>But I am getting empty response instead of expected response
  can you please help me how to do this,
  thank you for your help</p>