'Issue creating URL Connection with the url having "%E2%80%93"
I'm trying to download file from the following URL File URL. The problem is when I try to read anything from open connection like header or stream, the Unescape(%e2%80%93) character in URL get replace by junk. following is my code sample.
String url = "https://www.hse.ie/eng/services/list/5/cancer/profinfo/chemoprotocols/lymphoma-myeloma/549-obinutuzumab-and-chop-therapy-%E2%80%93-21-day.pdf";
URL webURL = new URL(URLDecoder.decode(url, "UTF-8"));
HttpURLConnection httpUrlConnection = (HttpURLConnection) webURL.openConnection();
httpUrlConnection.setRequestProperty("User-Agent", USER_AGENT);
System.out.println("URL Before Checking Response Code : " + httpUrlConnection.getURL().toString());
System.out.println("Response Code : " + httpUrlConnection.getResponseCode());
System.out.println("URL After Checking Response Code : " + httpUrlConnection.getURL().toString());
The output in console is as follows
URL Before Checking Response Code : https://www.hse.ie/eng/services/list/5/cancer/profinfo/chemoprotocols/lymphoma-myeloma/549-obinutuzumab-and-chop-therapy-–-21-day.pdf
Response Code : 400
URL After Checking Response Code : https://www.hse.ie/eng/services/list/5/cancer/profinfo/chemoprotocols/lymphoma-myeloma/549-obinutuzumab-and-chop-therapy-ãÃââÃâãââ¬Å¡Ã¢ÃâãÃââââ¬Å¡Ã£ââ¬Å¡Ã¢Ã£Ã£ÃââÃâãââ¬Å¡Ã¢ââ¬Å¡Ã£Ãââââ¬Å¡Ã£ââ¬Å¡Ã¢Ã¢Ã£ÃââÃâãââ¬Å¡Ã¢ÃâãÃââââ¬Å¡Ã£ââ¬Å¡Ã¢Ã¢Ã£ÃââÃâãââ¬Å¡Ã¢Ã¢Ã£Ãâââãââ¬Å¡Ã¢ââ¬Ã£ââ¬Å¡Ã¢Ã¡Ã£Ãââââ¬Å¡Ã£ââ¬Å¡Ã¢Ã¬Ã£ÃââÃâãââ¬Å¡Ã¢ÃâãÃââââ¬Å¡Ã£ââ¬Å¡Ã¢Ã¢Ã£ÃââÃâãââ¬Å¡Ã¢Ã¢Ã£Ãâââãââ¬Å¡Ã¢ââ¬Å¡Ã£ââ¬Å¡Ã¢Ã¬Ã£Ãââââ¬Â¦Ã£ââ¬Å¡Ã¢ââ¬Å-21-day.pdf
Solution 1:[1]
try to replace UTF-8 by ISO-8859-1 or try to replace % by there html code % or %25 or % or try to put your URL on textfild and set the font arial
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Omar Guermoudi |
