title: Unable to do HTTP POST from J2ME (Nokia S40 6thEdition)
body: <p>Im unable to do HTTP POST using J2ME below is the code that im using which is throwing an exception when I try and write to the OutputStrem. </p>
  
  <p>In the code Below SYSO prints "here5". Please need some guidance. Basically I've put the http connection part in a separate threads run method, to keep it aloof from the UI thread. </p>
  
  <pre><code>public void run(){
      HttpConnection http = null;
      OutputStream out = null;
      String msg = "lat=10&amp;long=20&amp;mac=923873";
      try{
      String url = "http://xxxx.php"; 
      byte[] data = null;
      InputStream istrm = null;
  
      http = (HttpConnection)Connector.open(url);
      }
      catch(Exception e)
      {
          System.out.println("here1");
      }
      try
      {
          http.setRequestMethod(HttpConnection.POST);
      }
      catch(Exception e)
      {
          System.out.println("here2");
      }
  
      try{
          http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
          http.setRequestProperty("User-Agent", "HttpMidlet/0.2");
          http.setRequestProperty("Custom-Property", "MyCustomProperty/1.0; AnotherProperty/debug_0.1");
  
          http.setRequestProperty("Content-Length", ""+msg.getBytes().length);
      }
      catch(Exception e)
      {
          System.out.println("here3");
      }
  
      try{
  
          out = http.openOutputStream();
      }
      catch(Exception e)
      {
          System.out.println("here4");
      }
      try{
      out.write(msg.getBytes());
      out.flush();
      }
      catch(Exception e)
      {
          System.out.println("here5");
      }
  
  }
  </code></pre>