欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

java.lang.IllegalArgumentException: URLDecoder异常解决

发布时间:2024/8/23 43 豆豆
生活随笔 收集整理的这篇文章主要介绍了 java.lang.IllegalArgumentException: URLDecoder异常解决 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

异常:

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中是特殊字符,需要特殊转义一下,

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

解决:

url = url.replaceAll("%(?![0-9a-fA-F]{2})", "%25");String urlStr = URLDecoder.decode(url, "UTF-8");

转载地址:https://blog.csdn.net/afgasdg/article/details/40304817

总结

以上是生活随笔为你收集整理的java.lang.IllegalArgumentException: URLDecoder异常解决的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。