2

我正在尝试使用 http post call 将视频文件上传到 amazons3。在这里,我首先在 android 上使用 okhttp 从中获取了签名的 url。这工作得很好。后来在这个网址上上传,我使用了 okHttp,后来创建了一个 httpconnection 对象并尝试了它。我尝试上传时不断收到 SSLException 错误。

        public void uploadObject(URL url, ContentResolver contentResolver, Uri uri) {

    //System.setProperty("jsse.enableSNIExtension", "false");
    HttpURLConnection connection = null;
    OutputStream dos = null;
    InputStream input = null;
    DataInputStream dis = null;
    //FileInputStream fileInputStream = null; //Data
    //String responseFromServer = "";
    int bytesRead, bytesAvailable, buffersize;
    int maxBufferSize = 4096;
    byte[] buffer;

    try
    {
        //fileInputStream = new FileInputStream(new File(selectedPath) );
        input = contentResolver.openInputStream(uri);
        connection  = (HttpURLConnection) url.openConnection();
        connection.setChunkedStreamingMode(4096);
        connection.setDoOutput(true);
        //connection.setConnectTimeout(180000);
        connection.setUseCaches(true);
        connection.setRequestMethod("PUT");
        //connection.setRequestProperty("Connection", "Keep-Alive");
        connection.setRequestProperty("Content-Type", "application/octet-stream");
        //dos = new DataOutputStream(connection.getOutputStream());
        dos = connection.getOutputStream();
        bytesAvailable = input.available();
        buffersize = Math.min(bytesAvailable,maxBufferSize);
        buffer = new byte[buffersize];
        bytesRead = input.read(buffer,0,buffersize);
        int len;
        while(( len = input.read(buffer)) > 0 ) //while(bytesRead > 0)
        {
            dos.write(buffer,0,buffersize);
            //bytesAvailable = input.available();
            //buffersize = Math.min(bytesAvailable, maxBufferSize);
            //bytesRead = input.read(buffer, 0, buffersize);
        }
        dos.flush(); dos.close();
    } catch (MalformedURLException mu) {
        Log.e(APIConfig.HTTP_TAG, "Error url:: "+ mu.getMessage());
        mu.printStackTrace();
    } catch(SSLProtocolException ssl) {
        Log.e(APIConfig.HTTP_TAG, "Error Client ssl:: " + ssl.getMessage());
        ssl.printStackTrace();
    } catch(IOException io) {
        Log.e(APIConfig.HTTP_TAG, "Error Client IO:: "+ io.getMessage());
        io.printStackTrace();
    }

    try
    {
        if(null!=connection) {
            dis = new DataInputStream(connection.getInputStream());
            String line;
            while ((line = dis.readLine())!=null) {
                Log.d(APIConfig.HTTP_TAG,"Server Response :: "+ line);
            }
            dis.close();
            //Log.d(APIConfig.HTTP_TAG,"Server Response :: "+ connection.getResponseMessage());
        }
    } catch (IOException ioex) {
        Log.e(APIConfig.HTTP_TAG, "Error:: Server response "+ ioex.getMessage());
        ioex.printStackTrace();
    }
    if(null!=connection)
    connection.disconnect();
}

这是它的错误堆栈-

        javax.net.ssl.SSLException: Write error: ssl=0xb8678db8: I/O error during system call, Connection reset by peer
10-26 11:28:07.119 652-748/     at com.android.org.conscrypt.NativeCrypto.SSL_write(Native Method)
10-26 11:28:07.120 652-748/     at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:740)
10-26 11:28:07.120 652-748/     at com.android.okio.Okio$1.write(Okio.java:70)
10-26 11:28:07.120 652-748/     at com.android.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:116)
10-26 11:28:07.120 652-748/     at com.android.okio.RealBufferedSink.write(RealBufferedSink.java:44)
10-26 11:28:07.120 652-748/     at com.android.okhttp.internal.http.HttpConnection$ChunkedSink.write(HttpConnection.java:330)
10-26 11:28:07.120 652-748/     at com.android.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:116)
10-26 11:28:07.121 652-748/     at com.android.okio.RealBufferedSink$1.write(RealBufferedSink.java:131)

10-26 11:28:07.128 652-748/     Error:: Server response Write error: ssl=0xb8678db8: Failure in SSL library, usually a protocol error
10-26 11:28:07.128 652-748/     javax.net.ssl.SSLProtocolException: Write error: ssl=0xb8678db8: Failure in SSL library, usually a protocol error
10-26 11:28:07.129 652-748/     at com.android.org.conscrypt.NativeCrypto.SSL_write(Native Method)
10-26 11:28:07.129 652-748/     at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:740)
10-26 11:28:07.130 652-748/     at com.android.okio.Okio$1.write(Okio.java:70)
10-26 11:28:07.130 652-748/     at com.android.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:116)
10-26 11:28:07.130 652-748/     at com.android.okio.RealBufferedSink.write(RealBufferedSink.java:62)
10-26 11:28:07.130 652-748/     at com.android.okhttp.internal.http.HttpConnection$ChunkedSink.close(HttpConnection.java:342)
10-26 11:28:07.130 652-748/     at com.android.okio.RealBufferedSink.close(RealBufferedSink.java:174)
10-26 11:28:07.130 652-748/     at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:605)
10-26 11:28:07.130 652-748/     at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:379)
10-26 11:28:07.130 652-748/     at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:323)
10-26 11:28:07.130 652-748/     at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:190)
10-26 11:28:07.130 652-748/     at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
10-26 11:28:07.130 652-748/     at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25)
4

0 回答 0