国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

后置中間件中獲取響應(yīng)主體內(nèi)容,并轉(zhuǎn)換為json格式返回

windss

問題描述

接口返回數(shù)據(jù)用數(shù)組,打算在后置中間件中把數(shù)組轉(zhuǎn)換為json返回給前端,如何在后置中間件里獲取response主體內(nèi)容,并轉(zhuǎn)換為json?
嘗試用$response->rawBody
就想在中間件中實(shí)現(xiàn),不要推薦其它方案,如果需要其它方案,就不會在這提問了

RegController 接口代碼

namespace app\api\controller;

use support\Request;

class RegController{
    public function reg(Request $req){
        $param = [
            'status'=>1
        ];
        return showReturnCode(200,$param,'success'); //返回的是數(shù)組

    }
}

后置中間件代碼

namespace app\api\middleware;

use Webman\Http\Request;
use Webman\Http\Response;
use Webman\MiddlewareInterface;

class ResJsonMiddleware implements MiddlewareInterface {
    public function process(Request $request, callable $handler): Response {
        $response = $handler($request);
        $rawBody = $response->rawBody();
        print_r($rawBody);   //只打印 Array 這幾個字符
        return $response;
    }
}
909 1 0
1個回答

walkor 打賞

控制器不支持返回數(shù)組

年代過于久遠(yuǎn),無法發(fā)表回答
??