Note that there are some explanatory texts on larger screens.

plurals
  1. POssl on android strange issue
    primarykey
    data
    text
    <p>I am trying to upload a file to some url using ssl. I use this code to set trust manager - </p> <pre><code>public static void trustAll () { TrustManage[] trustEverythingTrustManager = new TrustManager[] { new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { // TODO Auto-generated method stub } public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { // TODO Auto-generated method stub } public X509Certificate[] getAcceptedIssuers() { // TODO Auto-generated method stub return null; } } }; SSLContext sc; try { sc = SSLContext.getInstance("TLS"); sc.init(null, trustEverythingTrustManager, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (Exception e) { } } </code></pre> <p>and this one to set host name verifier - </p> <pre><code>public static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }; </code></pre> <p>then i am opening connection like this - </p> <pre><code>URL url = new URL("some_url"); HttpURLConnection connection = null; // check if this is https or just http if (url.getProtocol().toLowerCase().equals("https")) { trustAll(); HttpsURLConnection https = (HttpsURLConnection) url.openConnection(); https.setHostnameVerifier(DO_NOT_VERIFY); connection = https; } else { connection = (HttpURLConnection) url.openConnection(); } </code></pre> <p>After i get the connection i use it to upload the data. Is i use http everything is ok but when i try https i get the following exception - </p> <p>Write error: I/O error during system call, Broken pipe java.io.IOException: Write error: I/O error during system call, Broken pipe at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.nativewrite(Native Method) at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.access$600(OpenSSLSocketImpl.java:55) at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:565) at java.io.OutputStream.write(OutputStream.java:82) at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection$HttpOutputStream.write(HttpURLConnection.java:652) at java.io.DataOutputStream.write(DataOutputStream.java:101)</p> <p>The strange thing is that i don't get exception all the time. When i try to upload small files (200K) it's working O.K. or it's crashing very rare but when i try to upload bigger ones (more than 1MB) i get the exception almost every time.</p> <p>Any ideas ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload