【URLDecoder】java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in es
Java调用 URLDecoder.decode(str, "UTF-8"); 抛出以上的异常,其主要原因是% 在URL中是特殊字符,需要特殊转义一下,
上面的字符串中'%'是一个中文字符'是',而转换的实现是将%后面的两个字符一起转为一个16进制数。拿"%是"来转换数字,肯定会有NumberFormatException异常。
类似的如果请求字符串中有'+',也会有问题。因为'+'被当做空格使用了。
一个解决办法就是将%替换为%25。
data = data.replaceAll("%(?![0-9a-fA-F]{2})", "%25");
data = data.replaceAll("\\+", "%2B");
data = URLDecoder.decode(data, "utf-8");
这里使用了一个特殊正则表达式:零宽负向先行断言(zero-width negative lookahead assertion),模式为(?!pattern),代表字符串中的一个位置,紧接该位置之后的字符序列不能匹配pattern。%(?![0-9a-fA-F]{2})意思是'%'开始,但是后面两个字符不是数字,也不是字母。
【URLDecoder】java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in es的更多相关文章
- 【Cookie】java.lang.IllegalArgumentException An invalid character [32] was present in the Cookie value
创建时间:6.30 java.lang.IllegalArgumentException: An invalid character [32] was present in the Cookie va ...
- 【myBatis】java.lang.IllegalArgumentException: No enum constant org.apache.ibatis.type.JdbcType.NUMBE
可能#{current_date, jdbcType=VARCHAR}中的VARCHAR类型不对
- java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: " 0"
value = URLDecoder.decode(request.getParameter(paraName), "UTF-8"); 前端用了 encodeURI 来编码参数,后 ...
- java转换编码报错java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern
Exception in thread "main" java.lang.IllegalArgumentException: URLDecoder: Illegal hex cha ...
- shiro : java.lang.IllegalArgumentException: Odd number of characters.
shiro使用的时候: java.lang.IllegalArgumentException: Odd number of characters. at org.apache.shiro.cod ...
- 【Spring】java.lang.IndexOutOfBoundsException: Index: 256, Size: 256
Spring接受前台的数据超过256出现例如以下异常: org.springframework.beans.InvalidPropertyException: Invalid property 'sp ...
- 【转】java.lang.OutOfMemoryError: Java heap space的解决
原文地址:http://blog.sina.com.cn/s/blog_4b12778b0100v0bb.html Myeclipse下java.lang.OutOfMemoryError: Java ...
- 【异常】java.lang.NoClassDefFoundError: com/lowagie/text/pdf/PdfContentByte
异常信息: java.lang.NoClassDefFoundError: com/lowagie/text/pdf/PdfContentByte at com.star.sms.busines ...
- 【异常】java.lang.LinkageError: loader constraints violated
[问题背景] 南非客户帐单提醒功能过程中的一个问题,当启动服务器后,后台报java.lang.LinkageError: loader constraints violated when l ...
随机推荐
- 对 Visual Studio 中的Resharper禁用对某种文件的检测
原因:在Visual Studio中安装Reshaper后,就会对各种文件进行代码检测,但是因为Reshaper更新的速度不是很及时,所以有时会对Visual Studio中某些新功能误断,导致Cod ...
- 【Python数据分析】Python3操作Excel(二) 一些问题的解决与优化
继上一篇[Python数据分析]Python3操作Excel-以豆瓣图书Top250为例 对豆瓣图书Top250进行爬取以后,鉴于还有一些问题没有解决,所以进行了进一步的交流讨论,这期间得到了一只尼玛 ...
- c# 传递Null的string值导致的调用C++的dll报错 Attempted to read or write protected memory.
c# 调用C++的dll报错 Attempted to read or write protected memory: 原因是:c# 传递Null的string值导致的,将Null改为string ...
- 验证LeetCode Surrounded Regions 包围区域的DFS方法
在LeetCode中的Surrounded Regions 包围区域这道题中,我们发现用DFS方法中的最后一个条件必须是j > 1,如下面的红色字体所示,如果写成j > 0的话无法通过OJ ...
- 在WebAPI使用Session
最近在改写WebApp时要将以前用泛型处理例程写的Captcha 改成使用WebApi 来实作机制,在实作的过程中发现使用IRequiresSessionState session也无法使用(cont ...
- ionic angularJS input 相关指令 以及定时器 的使用
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" conte ...
- Java Collection
在 Java2中,有一套设计优良的接口和类组成了Java集合框架Collection,使程序员操作成批的数据或对象元素极为方便.这些接口和类有很多对抽象数据类型操作的API,而这是我们常用的且在数据结 ...
- python基础-修改haproxy配置文件
需要掌握的知识: 1.函数 2.文件处理 3.tag的用法 4.程序的解耦 需求: 1:查询 2:添加 3:删除 4:修改 5:退出 haproxy.conf 配置文件内容: global log 1 ...
- 泛型-List<T>
声明一个int类型的泛型对象 List<int> list=new List<int>(); list.Add(44);//不用装箱 int i1=list[0];//也不会发 ...
- 解决:error: Cannot fetch repo (TypeError: expected string or buffer)
同步源码,问题重现: Fetching project platform/external/libopus Fetching project repo error: Cannot fetch repo ...