springboot项目,在接收text/plain格式的时候,无法通过@requestBody得到请求中的json信息,需要对请求中的参数进行解析。
异常 type 'text/plain;charset=UTF-8' not supported。
/**
* 解析text/plain格式请求中的json
*
* @param request
* @return
*/
public static String fetchPostByTextPlain(HttpServletRequest request) {
try {
BufferedReader reader = request.getReader();
char[] buf = new char[512];
int len = 0;
StringBuffer contentBuffer = new StringBuffer();
while ((len = reader.read(buf)) != -1) {
contentBuffer.append(buf, 0, len);
}
return contentBuffer.toString();
} catch (IOException e) {
e.printStackTrace();
log.error("[获取request中用POST方式“Content-type”是“text/plain”发送的json数据]异常:{}", e.getCause());
}
return "";
}