title: Cannot POST or GET data onto Web Server from Android
body: <p>I had try to POST a simple query string (<code>tag=register&amp;uname....</code>)</p>
  
  <p>But it seems that the parameters are not sent to the local web server  (Apache)  </p>
  
  <p>Below is a piece of the ANDROID code I'm using. </p>
  
  <p>I know that the POST didn't work because the result sent back to ANDROID is a  null JSON object</p>
  
  <pre><code>public JSONObject getJSONFromUrl(String url, List&lt;Pair&lt;String, String&gt;&gt; params) throws MalformedURLException {
  
      // _url = http://192.168.0.10/ibiti_api/
      URL _url = null;
      String dataToPost = null;
      try {
          dataToPost = this.getQuery(params);
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      }
      //getQuery(params) send back a string like : tag=register&amp;uname=....
      HttpURLConnection urlConnection = null;
      OutputStreamWriter wr = null;
      JSONObject _oUser = null;
      try {
          _url = new URL(url);
          urlConnection = (HttpURLConnection)_url.openConnection();
          urlConnection.setRequestMethod("POST");
          //urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
          //urlConnection.setRequestProperty( "Accept", "*/*" );
          urlConnection.setDoInput(true);
          urlConnection.setDoOutput(true);
          urlConnection.setChunkedStreamingMode(0);
         // urlConnection.connect();
          //POST request
          wr = new OutputStreamWriter(urlConnection.getOutputStream ());
          wr.write(dataToPost);
          in = urlConnection.getInputStream();
          //wr.flush();
          _oUser =  readStream(in); // Result is an objet null because nothing is POST
          wr.close();
          in.close();
          urlConnection.disconnect();
  
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      return _oUser;
  
  }
  </code></pre>