44 网友分享了链接
2020-08-28 08:07:56
在过滤器里先先解析成json对象,递归属性值,把每一个属性分别过滤
然后再转成byte放到请求体里即可啦
差不多长这样 //xss过滤
JSONObject jsonObject = JSON.parseObject(json);
for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
if (entry.getValue() != null) {
if (entry.getValue() instanceof String) {
String a = xssEncode(entry.getValue().toString());
entry.setValue(a);
}
}
jsonObject.put(entry.getKey(), entry.getValue());
}
final ByteArrayInputStream bis = new ByteArrayInputStream(jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8));