简体   繁体   中英

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. For example, for the link http://dl.androidiha.com/games/Dead-Rider-v2.5.2[Androidiha.com].zip error is as below :

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

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. How to deal with the URISyntaxException

I am sure you can solve the problem in a similar way

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM