在三星 C6112 手机上,m 面临着奇怪的问题。
我的 midlet 应用程序正在尝试连接到 HTTPS url。(它托管在带有 Versign 证书的 IIS 6.0 Web 服务器上)。
我正在使用 POST 方法发送数据。写完发布数据后,我调用outputstream.flush()和 outputstream.close()方法。这两个方法给出“ InterruptedIOException or IOException:TCP open ”。
如果我评论这两种方法,即 .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 手机。