title: How do i POST in java to a server?
body: <p>I want to send for example a string "hello world" through a stream to a server.</p>
  
  <p>So far i did:</p>
  
  <pre><code>private void PostData() {
  
          HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
          try {
              urlConnection.setDoOutput(true);
              urlConnection.setChunkedStreamingMode(0);
  
              OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
              writeStream(out);
  
              InputStream in = new BufferedInputStream(urlConnection.getInputStream());
              readStream(in);
              finally {
                  urlConnection.disconnect();
              }
          }
      }
  </code></pre>
  
  <p>But not sure where do i put the ip and port of the server i want to send the data to ?</p>
  
  <p>Where do i put the string i want to send for example "hello world" ?</p>
  
  <p>And i'm getting errors on this method:</p>
  
  <pre><code>HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
  </code></pre>
  
  <p>On the url: Cannot resolve symbol url</p>
  
  <pre><code>OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
  </code></pre>
  
  <p>On the urlConnection.getOutputStream() unhandled exception.</p>
  
  <p>On </p>
  
  <pre><code>writeStream(out);
  </code></pre>
  
  <p>Cannot resolve method writeStream</p>
  
  <p>Same for readStream</p>
  
  <p>And in the end on finally: finally without try</p>
  
  <p>I took the example from the offical developers android com:</p>
  
  <p><a href="http://developer.android.com/reference/java/net/HttpURLConnection.html" rel="nofollow">Developers android</a></p>