title: J2ME HttpConnection getResponseCode() blocks waiting answer from server on Nokia N97
body: <p>I upload a file from a Nokia N97 phone to server, everything works fine but after file is uploaded I want to get response from server. The problem is that I get response only after half a minute or more. From what I see the code blocks in httpConnection.getResponseCode() waiting for response. I tested it on a Sony Ericsson and I get response very fast so I assume is a Nokia N97 problem. (is not a server problem because it works fine on other phones)</p>
  
  <p>Does anyone knows why this thing happens only on Nokia?</p>
  
  <p>Here is a code snippet:</p>
  
  <p>public uploadFile() {</p>
  
  <pre><code>       httpConn = (HttpsConnection) Connector.open(url, Connector.READ_WRITE);
          ...
         //set httpConn parameters and request method 
         ...
  
         writeParametersAndFileName(os, "text/plain");
  
  
         **writeFileToStream(os);** 
  
         os.write("\r\n".getBytes());
         os.write("--".getBytes());
  
         os.write(boundary.getBytes());
  
         os.write("--".getBytes());
         os.write("\r\n".getBytes());
  
          *//here code blocks on Nokia N97. Same thing happens if I use os.flush() after
          // I send chunks of the file*
           .....
          codeResp = httpConn.getResponseCode();
          // check condition
          checkResponseHeader();
  </code></pre>
  
  <p>}</p>
  
  <p>public <strong>writeFileToStream()</strong> {</p>
  
  <pre><code>        InputStream is = null;
          FileConnection c = null;
          try
          {
             c = (FileConnection) Connector.open("file:///"+ sourcePath, Connector.READ);
  
             if(c.exists()) {
                 is = c.openInputStream();
  
                 long fs = c.fileSize();
                 while (total &lt; fs) {
                      byte[] data = new byte[512];
                      int readAmount = is.read(data,0,512);                       
                      total += readAmount;
                      os.write(data, 0, readAmount);
  
  
              }
  
              //os.flush();
          }
          catch (IOException ex) {
             //               
          }
          finally
          {
             //close connection
  
          }
  </code></pre>
  
  <p>}</p>