0

アプリケーションに Spark フレームワークを使用しています。

本文が JSON 形式であるかどうかを (特に) チェックするミドルウェアがあります。

    // Middleware
    before((req, res) -> {
        // Method check
        if (!req.requestMethod().equals("POST")) {
            halt(403, "{\"result\":\"ERR\",\"errMsg\":\"Only POST allowed!\",\"code\":403}");
        }
        // JSON Check
        JSONObject body_json = new JSONObject();
        try {
            body_json = new JSONObject(req.body());
        } catch (JSONException e) {
            halt(403, "{\"result\":\"ERR\",\"errMsg\":\"No valid JSON!\",\"code\":403}");
        }
        // At this point (end of middleware) the request body is still unchanged !
    });

次に、POST リクエストを処理するための通常の機能があります。

post("/post_some_data", (req, res) -> {
     String body = req.body()           // This string is empty !!
     int length = req.contentLength();  // This remain unchanged       
});

しかし、リクエストの本文は突然空になります (他の属性とヘッダーは変更されません)。

それはバグですか、それとも何か間違っていますか??

4

1 に答える 1

1

spark フレームワークにバグがありました。ライブラリを 2.1 バージョンに更新すると、この問題と同様の問題がすべて解決されます。

于 2014-12-27T13:03:23.560 に答える