title: Android: connect httpURLConnection to the server
body: <p>I want to send JSON string to the server every 60 seconds with <code>HttpURLConnection</code> API. I am running the app on my smartphone device, which is connected to the laptop via USB cable. With this URL <code>http://zzzzz.byethost8.com/connection.php</code> I am getting the code <code>500</code> as output of <code>getResponseCode()</code>. I even tried it with the wamp server, but I am not getting any output there.</p>
  
  <p>For WAMP I used this URL: <code>http://192.168.134.45/connection.php</code> where <code>192.168.134.45</code> is my Wi-Fi IP address.</p>
  
  <p>JSON String:</p>
  
  <pre><code>{
      "latitude":80.86898504,
      "longitude":20.66561187,
      "time":"26.04.2015 12:45:11",
      "route":4
  }
  </code></pre>
  
  <p>The implementation of <code>doInBackground()</code> method:</p>
  
  <pre><code>protected Void doInBackground(String... params) {
      // TODO Auto-generated method stub
  
      try {
          System.out.println("The output of : doInBackground " +params[0]);
  
          //URL myUrl = new URL("http://byethost8.com/connection.php");
          URL myUrl = new URL("http://192.168.182.15/connection.php");
          HttpURLConnection conn = (HttpURLConnection) myUrl.openConnection();
          conn.setRequestMethod("POST");
          conn.setDoOutput(true);
          conn.setConnectTimeout(10000);
          conn.setReadTimeout(10000);
          conn.setRequestProperty("Content-Type", "application/json");
          System.out.println("The output of getResponsecode: "+conn.getResponseCode());
          conn.connect();
          // create data output stream
          DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
          // write to the output stream from the string
          wr.writeBytes(params[0]);
          wr.close();
  
      } catch (IOException e) {
  
          e.printStackTrace();
      }
      return null;
  
  }
  </code></pre>
  
  <p>PHP connection file with the default WAMP setting.</p>
  
  <pre><code>&lt;?php
   $json = json_decode(file_get_contents('php://input', true));
  
   //hotname-username-password-datebase.
   $db = new mysqli("sql209.byethost8.com", "b8_16138121", "fadi88", "b8_16138121_busTracker");  
   echo "You are in!";
   if ($db-&gt;connect_errno) {
      die("We are sorry, you could not be connected to the server,
          please check your connection setting!");
   }
  ?&gt;
  </code></pre>