1

我想从 reome URL 下载图像,但出现 SSL 错误

 String imgURL="http://whootin.s3.amazonaws.com/uploads/upload/0/0/23/82/Note_03_26_2013_01_10_55_68.jpg?AWSAccessKeyId=AKIAJF5QHW2P5ZLAGVDQ&Signature=Za4yG0YKS4%2FgoxSidFsZaAA8vWQ%3D&Expires=1364888750";

   final ImageView  ivCurrent;
   ivCurrent = (ImageView)findViewById(R.id.imageView1);

  // calling DownloadAndReadImage class to load and save image in sd card

     DownloadAndReadImage dImage= new DownloadAndReadImage(imgURL,1);

     ivCurrent.setImageBitmap(dImage.getBitmapImage());

错误:

javax.net.ssl.SSLException: Read error: ssl=0x19a4a0: I/O error during system call, Connection reset by peer
4

3 回答 3

1

您的问题毫无意义,因为我们对类一无所知DownloadAndReadImage,顺便说一句,我认为您需要在清单中添加这两个权限:

 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

PS 如果您正在寻找一个很棒的ImageLoder库,我建议您使用 Android Universal Image Loader:

https://github.com/nostra13/Android-Universal-Image-Loader

于 2013-04-01T13:59:09.817 回答
0

在我的项目中,我使用InputStreams以下方式下载图像并将其存储在 SD 卡中:

URL url = new URL(imageUrl);

InputStream input = url.openStream();

try {

    // The sdcard directory e.g. '/sdcard' can be used directly, or
    // more safely abstracted with getExternalStorageDirectory()
    String storagePath = Environment.getExternalStorageDirectory()
                                    .getAbsolutePath();

    int barIndex = imageUrl.indexOf("/");
    String path = imageUrl.substring(barIndex + 1) + ".jpg";

    String sdcardPath = storagePath + "/myapp/";

    File sdcardPathDir = new File(sdcardPath);

    sdcardPathDir.mkdirs();

    OutputStream output = new FileOutputStream(sdcardPath + imagemId + ".jpg");

    try {
        byte[] buffer = new byte[4 * 1024];
        int bytesRead = 0;
        while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
            output.write(buffer, 0, bytesRead);
        }
    } finally {
        output.close();
    }

} finally {
    input.close();
}

正如@NullPointer 指出的那样,不要忘记检查清单文件:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
于 2013-04-01T13:58:20.563 回答
0

您正在连接到 HTTPS/HTTP URL,并且该站点提供的 SSL 证书不受您运行代码的设备的信任。

建立对 Apache HTTP 客户端的信任

于 2013-04-01T14:07:22.133 回答