2

AngularJS を使用して Moqui とやり取りしているときに、実行コンテキストでのパラメーターの追加に関する問題があるようです。

リクエスト ヘッダーの content-type は、自動的に に設定され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}")
}

application/json; charset=UTF-8このコードは、Content-Type が に設定され、パラメーターがコンテキストに自動的に追加されない場合を考慮していません。

application/jsoncontent-type の部分文字列としてチェックする条件があるべきではありませんか?

4

0 に答える 0