【问题标题】:Samsung C6112 (J2ME handset) InterruptedIOException issue三星 C6112(J2ME 手机)InterruptedIOException 问题
【发布时间】:2012-01-18 14:07:07
【问题描述】:

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

我的 midlet 应用程序正在尝试连接到 HTTPS url。 (它托管在带有 Versign 证书的 IIS 6.0 Web 服务器上)。

我正在使用 POST 方法发送数据。写完帖子数据后,我调用 outputstream.flush()outputstream.close() 方法。这两个方法给出“InterruptedIOExceptionIOException: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 手机。

【问题讨论】:

    标签: iis java-me https ioexception samsung-mobile


    【解决方案1】:

    试试这个,

    而不是,

    dos = hc.openOutputStream();
    

    试试这个,

    dos = (OutputStream) hc.openOutputStream();
    

    而不是,

    is = hc.openInputStream();
    

    试试这个,

    is = (InputStream) hc.openInputStream();
    

    但是我建议你使用DataInputStream & DataOutputStream 类来进行这些操作。

    【讨论】:

    • 嘿路西法,谢谢你的回复。我已经尝试过你的解决方案,但仍然给出“InterruptedIOexception”。
    • 是的,你需要在 is = hc.openInputStream() 行后面写 .getResponseCode() 。
    • okies,你能评论你的这些行吗 dos.flush(); & dos.close();现在运行程序。
    • 在 is = hc.openInputStream() 上遇到 iterruptedIOException 错误;行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多