2012-01-18 78 views
0

在三星C6112手机上,m面临奇怪的问题。三星C6112(J2ME手机)InterruptedIOException问题

我的midlet应用程序试图连接到HTTPS url。 (其托管在具有版本证书的IIS 6.0 Web服务器上)。

我使用POST方法发送数据。在写完帖子数据后,我打电话outputstream.flush()outputstream.close()方法。这两种方法给出“InterruptedIOExceptionIOException:TCP打开”。

如果我评论两种方法,即.flush()和.close(),hc.openInputStream();抛出相同的异常。

下面的示例代码,如果有什么问题,请告诉我。

InputStream is = null; 
OutputStream dos = null; 
HttpConnection hc = null; 
try { 
     hc = (HttpConnection) Connector.open(url,Connector.READ_WRITE,true); 

     byte b1[] = "Hello_World".getBytes(); 

     hc.setRequestMethod(HttpConnection.POST); 

     dos = hc.openOutputStream(); 

     int i = 0; 
     while (i < b1.length) { 
      dos.write(b1[i]); 
      i++; 
     } 
     dos.write("\r\n".getBytes()); 

     dos.flush(); // gives **InterruptedIOException** or **IOException:TCP open** 
     dos.close(); // gives **InterruptedIOException** or **IOException:TCP open** 

     is = hc.openInputStream(); 

     byte b[]; 
     ByteArrayOutputStream bStrm = new ByteArrayOutputStream(); 
     int ch, downloadedData=0; 
     while ((ch = is.read()) != -1) { 
      downloadedData++; 
      bStrm.write(ch); 
     } 
     b = bStrm.toByteArray(); 

    } catch (javax.microedition.pki.CertificateException ce) { 
     System.out.println("CertificateException in " + ce.toString()); 
    } catch (SecurityException se) { 
     System.out.println("SecurityException: ", se.toString()); 
    } catch (ConnectionNotFoundException cnfe) { 
     System.out.println("ConnectionNotFoundException: ", cnfe.toString()); 
    } catch (IOException ioe) { 
     System.out.println("IOException: ", ioe.toString() + ioe.getMessage()); 
    } catch (Exception e) { 
     System.out.println("Exception: ", e.toString()); 
    } finally { 
     if (hc != null) { 
      try { 
       hc.close(); 
       hc = null; 
      } catch (Exception e) { 
       e.printStackTrace(); 
       System.out.println("finally hc.close(); IOException " + e.getMessage() + " " + e.toString()); 
      } 
     } 

     if(is !=null) { 
      try { 
       is.close(); 
      } catch (Exception e) { 
       e.printStackTrace(); 
       System.out.println("finally is.close(); Exception " + e.getMessage() + " " + e.toString()); 
      } 
     } 
    } 

请让我知道如何处理三星j2me手机。

回答

0

试试这个,

代替,

dos = hc.openOutputStream(); 

试试这个,

dos = (OutputStream) hc.openOutputStream(); 

,而不是和,

is = hc.openInputStream(); 

试试这个,

is = (InputStream) hc.openInputStream(); 

但是我想建议您使用DataInputStream & DataOutputStream类为这些操作。

+0

嘿路西法,谢谢你的回复。我尝试过你的解决方案,但仍然给“InterruptedIOexception”。 – Sandeep 2012-01-19 08:17:46

+0

你能上传你的最新代码吗? – Lucifer 2012-01-19 08:19:27

+0

是的,您需要在is = hc.openInputStream()行之后编写.getResponseCode()。 – Lucifer 2012-01-19 08:55:30