Java正确URL解码方式:URLDecoder.decode

    xiaoxiao2021-03-26  39

    [java]  view plain  copy   Exception in thread "main" java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "u9"      at java.net.URLDecoder.decode(URLDecoder.java:194)      at com.hbzx.controller.PayResultController.main(PayResultController.java:253)  

    Java调用 URLDecoder.decode(str, "UTF-8"); 抛出以上的异常,其主要原因是% 在URL中是特殊字符,需要特殊转义一下,

    解决办法:使用%替换字符串中的%号

        

    [java]  view plain  copy   url = url.replaceAll("%(?![0-9a-fA-F]{2})""%");    String urlStr = URLDecoder.decode(url, "UTF-8");  
    转载请注明原文地址: https://ju.6miu.com/read-662780.html

    最新回复(0)