Here, i give you one function that will remove all invalid characters from the url . Please pass your url in this function and you will get a new url with encoded strings.
public static String convertURL(String str) {
String url = null;
try{
url = new String(str.trim().replace(" ", "%20").replace("&", "%26")
.replace(",", "%2c").replace("(", "%28").replace(")", "%29")
.replace("!", "%21").replace("=", "%3D").replace("<", "%3C")
.replace(">", "%3E").replace("#", "%23").replace("$", "%24")
.replace("'", "%27").replace("*", "%2A").replace("-", "%2D")
.replace(".", "%2E").replace("/", "%2F").replace(":", "%3A")
.replace(";", "%3B").replace("?", "%3F").replace("@", "%40")
.replace("[", "%5B").replace("", "%5C").replace("]", "%5D")
.replace("_", "%5F").replace("`", "%60").replace("{", "%7B")
.replace("|", "%7C").replace("}", "%7D"));
}catch(Exception e){
e.printStackTrace();
}
return url;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…