I have a piece of code in an Android application which sends data to my server (to an HTTPS url) as such:
private void sendData(String serverUrl, byte[] message) {
HttpURLConnection conn = null;
try {
URL url = new URL(serverUrl);
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setFixedLengthStreamingMode(message.length);
conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
conn.setRequestProperty("X-Requested-With", "XMLHttpRequest");
OutputStream os = new BufferedOutputStream(conn.getOutputStream());
os.write(message);
os.flush();
conn.connect();
} catch (Exception e) {
//TODO: log exception and continue gracefully
} finally {
if (conn != null)
conn.disconnect();
}
}
However, I keep seeing the following exception occurring from time to time sporadically on some devices (usually Samsung with Jelly Beans versions [SDK 16, 17 or 18]):
org.apache.harmony.security.asn1.ASN1Exception: Wrong content for ASN.1 integer at [15].
An integer MUST be encoded in minimum number of octets
java.lang.RuntimeException: org.apache.harmony.security.asn1.ASN1Exception:
Wrong content for ASN.1 integer at [15]. An integer MUST be encoded in minimum number of octets
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:586)
at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:371)
at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:209)
at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:478)
at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:188)
at libcore.net.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:281)
at com.myapp.Reporter.sendData(Reporter.java:45)
I've searched the internet and google high and low but could not figure out what this means or how to resolve it.
Anyone has any idea?