简体   繁体   English

使用DefaultHttpClient下载时出现java.net.URISyntaxException

[英]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.

相关问题 java.net.URISyntaxException - java.net.URISyntaxException 当我尝试发布URL时java.net.URISyntaxException - java.net.URISyntaxException when i try to post a URL 提交 Spark 作业时是什么导致“java.net.URISyntaxException:绝对 URI 中的相对路径”? - What is causing "java.net.URISyntaxException: Relative path in absolute URI" when submit spark job? Android java.io.IOException:java.net.URISyntaxException: - Android java.io.IOException: java.net.URISyntaxException: 空间是工作空间名称引起java.net.URISyntaxException - Space is Worspace name is causing java.net.URISyntaxException 如何避免URL.toURI()中的java.net.URISyntaxException - How to avoid java.net.URISyntaxException in URL.toURI() java.net.URISyntaxException:JMETER 索引处的查询中存在非法字符 - java.net.URISyntaxException: Illegal character in query at index on JMETER java.net.URISyntaxException:索引 177 处的查询中存在非法字符 - java.net.URISyntaxException: Illegal character in query at index 177 Mac OS X 上 Netbeans 库中的 java.net.URISyntaxException - java.net.URISyntaxException in a library in Netbeans on Mac OS X java.net.URISyntaxException:在Weblogic中部署War时索引69处的字符无效 - java.net.URISyntaxException:Invalid character at index 69 when deploying war in weblogic
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM