url中带有加号(“x2B”)的Android
我无法下载图片: 这是我的代码: //从网络url中带有加号(“x2B”)的Android,android,Android,我无法下载图片: 这是我的代码: //从网络 try { Bitmap bitmap = null; URL imageUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) imageUrl .openConnection(); conn.setRequestProperty("Content-Type", "ap
try {
Bitmap bitmap = null;
URL imageUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) imageUrl
.openConnection();
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setConnectTimeout(25000);
conn.setReadTimeout(25000);
conn.setInstanceFollowRedirects(true);
InputStream is = conn.getInputStream();
OutputStream os = new FileOutputStream(f);
// save file to m_FileCache
copyStream(is, os);
os.close();
bitmap = decodeFile(f);
return bitmap;
} catch (Throwable ex) {
return null;
}
使用此代码,我可以下载所有图像URL,如下所示:
根本原因是第一个链接中的加号(“+”)。请帮帮我!多谢各位 您可以使用Uri生成器类。例如,
String url = Uri.parse("http://www.wallpick.com/wp-content/uploads/2014/02/08/").buildUpon()
.appendEncodedPath("Water+Sports_wallpapers_242-640x480.jpg")
.build().toString();
这将正确编码url字符串。将加号替换为相关的HTML编号:
+代码>此问题已得到回答:可能重复感谢您的回答!此链接已在服务器中删除。