javax.net.ssl.SSLException:写入错误:ssl = 0x7f70604080:系统调用期间的I / O错误,管道损坏

时间:2016-06-24 14:42:38

标签: android ssl retrofit

我使用改造将图片上传到服务器,但有一个奇怪的问题

api方法声明:

@POST("/uploadImage")
@Multipart
Result<UploadImageResponse> uploadImage(@Part("image") TypedByteArray image);

rest adapter user custom client:

OkClient client = new OkClient(getUnsafeOkHttpClient());

其中

private OkHttpClient getUnsafeOkHttpClient() {

    try {
        // Create a trust manager that does not validate certificate chains
        final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
            @Override
            public void checkClientTrusted(
                    java.security.cert.X509Certificate[] chain,
                    String authType) throws CertificateException {
            }

            @Override
            public void checkServerTrusted(
                    java.security.cert.X509Certificate[] chain,
                    String authType) throws CertificateException {
            }

            @Override
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }
        }};

        // Install the all-trusting trust manager
        final SSLContext sslContext = SSLContext.getInstance("SSL");
        sslContext.init(null, trustAllCerts,
                new java.security.SecureRandom());
        // Create an ssl socket factory with our all-trusting manager
        final SSLSocketFactory sslSocketFactory = sslContext
                .getSocketFactory();

        OkHttpClient okHttpClient = new OkHttpClient();
        okHttpClient.setSslSocketFactory(sslSocketFactory);
        okHttpClient.setHostnameVerifier(new HostnameVerifier() {

            @Override
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        });

        return okHttpClient;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

异常日志:

D/Retrofit: javax.net.ssl.SSLException: Write error: ssl=0x7f70604080: I/O error during system call, Broken pipe
                                                                   at com.android.org.conscrypt.NativeCrypto.SSL_write(Native Method)
                                                                   at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:771)
                                                                   at okio.Okio$1.write(Okio.java:80)
                                                                   at okio.AsyncTimeout$1.write(AsyncTimeout.java:155)
                                                                   at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
                                                                   at okio.RealBufferedSink.write(RealBufferedSink.java:46)
                                                                   at com.squareup.okhttp.internal.http.Http1xStream$FixedLengthSink.write(Http1xStream.java:288)
                                                                   at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
                                                                   at okio.RealBufferedSink$1.write(RealBufferedSink.java:198)
                                                                   at java.io.OutputStream.write(OutputStream.java:82)
                                                                   at retrofit.mime.TypedByteArray.writeTo(TypedByteArray.java:66)
                                                                   at retrofit.client.UrlConnectionClient.prepareRequest(UrlConnectionClient.java:68)
                                                                   at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:37)
                                                                   at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:321)
                                                                   at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
                                                                   at java.lang.reflect.Proxy.invoke(Proxy.java:393)
                                                                   at $Proxy3.uploadImage(Unknown Source)

1 个答案:

答案 0 :(得分:7)

此异常是服务器端文件限制的结果