当我使用AngularJS与Moqui交互时,在执行上下文中添加参数似乎存在问题。
请求标头的内容类型自动设置为application/json; charset=UTF-8
。但WebFacadeImpl.groovy
中用于处理application/json
请求的代码是
String contentType = request.getHeader("Content-Type")
if (contentType == "application/json" || contentType == "text/json" || contentType.matches("(.*)application/json(.*)")) {
JsonSlurper slurper = new JsonSlurper()
Object jsonObj = null
try {
jsonObj = slurper.parse(new BufferedReader(new InputStreamReader(request.getInputStream(),
request.getCharacterEncoding() ?: "UTF-8")))
} catch (Throwable t) {
logger.error("Error parsing HTTP request body JSON: ${t.toString()}", t)
jsonParameters = [_requestBodyJsonParseError:t.getMessage()]
}
if (jsonObj instanceof Map) {
jsonParameters = (Map<String, Object>) jsonObj
} else if (jsonObj instanceof List) {
jsonParameters = [_requestBodyJsonList:jsonObj]
}
// logger.warn("=========== Got JSON HTTP request body: ${jsonParameters}")
}
当Content-Type设置为application/json; charset=UTF-8
并且参数未自动添加到上下文时,此代码不考虑这种情况。
是否应该检查application/json
作为内容类型的子字符串的条件?