java.lang.IllegalArgumentException: Illegal character in query at index
程序员文章站
2024-02-14 17:06:34
...
这个报错是我写HttpPost推送数据的时候出错的,一开始我也不知道是什么问题,后面去找了一下发现是发送请求的参数出问题了
请求:
http://xxxxxx/xxxxx?datas=[{"sn":"AABBCC2","time":"2021-05-11 13:10:01","status":"1,1,2","eDToday":"1.5","eDTotal":"7.9"}]
然后就报错
java.lang.IllegalArgumentException: Illegal character in query at index
这个报错是因为你的参数是跟着地址后面一起发送请求,而在地址上面不能有什么大括号,空格,引号等等…这些符号,一旦加上就会发生未知符号报错。
所以我们要进行转换用以下代码把你的未知符号转换一下
try {
datas = URLEncoder.encode(json.getString("datas"), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
// TODO: handle exception
}
格式:URLEncoder.encode(字符串, “UTF-8”)
这样就ok了
推荐阅读
-
爬坑记(1):配置地址有空格,java.lang.IllegalArgumentException: Illegal character in path at index 52
-
SpringCloud错误:Illegal character in path at index 29: http://localhost:7000/eureka/ /
-
java.lang.IllegalArgumentException: Illegal character in query at index
-
java.lang.IllegalArgumentException: Illegal charactor in path at index 0 \demo_index\_search
-
Skywalking Illegal character in hostname at index
-
java.lang.IllegalArgumentException: Illegal character in query at index
-
启动JBoss出现“java.net.URISyntaxException: Illegal character in path at index 11”解决
-
java8中使用java.util.Base64报“java.lang.IllegalArgumentException: Illegal base64 character d”
-
ERROR: Illegal character in opaque part at index 2: F:\Android\.android\debug.keystore
-
java.lang.IllegalArgumentException: Illegal character in query at index 141: