1 Reply Latest reply: May 17, 2009 9:22 AM by 843851 RSS

    Connection is not open for Httpconnection

    843851
      Hi. I m using HttpConnection to connect to my servlet with POST Method.
      when i test my application in Sonic Erison that is work fine.
      But when i test with Nokia 6280 it throw ioException. and the message display "Connection is not open" but for my servlet site's console is display Success Access.

      If i use Get Method. This problem is not happend. so Anyone can help me . this is my code

      HttpConnection c = null;
      DataInputStream is = null;
      DataOutputStream os = null;
      StringBuffer b = new StringBuffer();
      String url = "http://test.com/FD2628/Login.do";
      try {


      String str = "USRLID="+name.trim()+"&PASSWORD="+pass.trim();
      //url = url+"?"+str;
      byte postmsg[] = str.getBytes();
      c = (HttpConnection)Connector.open(url,Connector.READ_WRITE);

      c.setRequestMethod(HttpConnection.POST);
      c.setRequestProperty("Content-type","application/x-www-form-urlencoded");
      c.setRequestProperty("IF-Modified-Since", "20 Jan 2001 16:19:14 GMT");
      c.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.0");
      c.setRequestProperty("Content-Language", "en-US");
      c.setRequestProperty( "Content-Length", new Integer(postmsg.length).toString());
      c.setRequestProperty("Connection", "close");
      // if(c.is)

      os = c.openDataOutputStream();



      os.write(postmsg);

      int response=0;
      // now get the response
      response=c.getResponseCode();
      System.out.println("Connection: "+response);
      if(response!=HttpConnection.HTTP_OK) {
      return false;
      }

      is = c.openDataInputStream();
      int ch;
      while ((ch = is.read()) != -1) {
      b.append((char) ch);
      }
      if(b.toString().trim().equals("1")){
      return true;
      }else{
      return false;
      }


      } finally {
      if(is!= null) {
      is.close();
      }

      if(c != null) {
      c.close();
      }
      if(os != null) {
      os.close();
      }
      }

      i found that the problem is on this line os = c.openDataOutputStream();