准备向后台传递一个可转为json对象的字符串:
message = "{'name':'新添json对象','id':1231,'inputParamList':[{'parameterName':'field','type':'string'}]}";
但只要添加[]就会遇到问题:触发get请求时报错HTTP Status 400
经搜索发现是由于tomcat高版本会拦截特殊字符,如[]
。
由于使用的是SpringBoot(v2.2.2.RELEASE)内置tomcat,看到有博主使用添加@Configuration
配置的方式解决,或者使用Post请求,而这两种方式都没有解决我的问题。
最后解决方式是使用:
message = encodeURI(message);
进行转义。
在此记录,希望可以帮到大家。
参考链接:
https://blog.csdn.net/tangran0526/article/details/99977240