[英]java.net.URISyntaxException when downloading with DefaultHttpClient
I have programmed a class that get file with creating some parallel downloads. 我编写了一个类,该类通过创建一些并行下载来获取文件。 I use the simple code as below for any download :
我使用以下简单代码进行任何下载:
DefaultHttpClient conn = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(new URI(M_url));
HttpResponse = conn.execute(httpPost);
In some file links ( M_url ) the program is okay, but when i want to download the link that contains the characters like [ ] URISyntaxException has occurred. 在某些文件链接( M_url )中,程序正常,但是当我要下载包含[] URISyntaxException之类的字符的链接时,发生了该情况。 For example, for the link
http://dl.androidiha.com/games/Dead-Rider-v2.5.2[Androidiha.com].zip
error is as below : 例如,对于链接
http://dl.androidiha.com/games/Dead-Rider-v2.5.2[Androidiha.com].zip
错误,如下所示:
java.net.URISyntaxException: Illegal character in path at index 48: http://dl.androidiha.com/games/Dead-Rider-v2.5.2[Androidiha.com].zipException in thread "main" java.lang.NullPointerException
java.net.URISyntaxException:索引48处路径中的非法字符:http://dl.androidiha.com/games/Dead-Rider-v2.5.2[Androidiha.com].zipException在线程“主”中java.lang.NullPointerException
What is the programmatically solution for solve this problem? 解决该问题的编程解决方案是什么? I use the following code, but this can't solve my problem :
我使用以下代码,但这不能解决我的问题:
M_url = URLEncoder.encode(M_url, "UTF-8")
Thanks in advance and sorry if this topic duplicates with similar one. 在此先感谢,如果本主题与相似的主题重复,则表示抱歉。
I believe encoding maybe the answer. 我相信编码也许是答案。 There is a similar topic existing on how to handle URISyntaxexception.
关于如何处理URISyntaxexception,存在类似的主题。 How to deal with the URISyntaxException
如何处理URISyntaxException
I am sure you can solve the problem in a similar way 我相信您可以通过类似的方式解决问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.