From fe1477626c5546fdaa772cbd66588ab7c8990a05 Mon Sep 17 00:00:00 2001 From: gaoolp Date: Mon, 11 Jan 2021 15:51:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3body=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E7=9A=84json=E8=AF=B7=E6=B1=82=EF=BC=8C=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=8A=A5=E9=94=99=EF=BC=9AUncaught=20TypeError:=20Argument=201?= =?UTF-8?q?=20passed=20to=20Symfony\\Component\\HttpFoundation\\ParameterB?= =?UTF-8?q?ag::=5F=5Fconstruct()=20must=20be=20of=20the=20type=20array,=20?= =?UTF-8?q?null=20given?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RPC/RpcProxy.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/RPC/RpcProxy.php b/src/RPC/RpcProxy.php index 962c8d0..ecad073 100644 --- a/src/RPC/RpcProxy.php +++ b/src/RPC/RpcProxy.php @@ -145,6 +145,10 @@ public function createRequest($actionName, Route $route, array $args) } } } + if ($body === null && $headers['Content-Type'] == 'application/json') { + // 解决body为空的json请求,接口报错:Uncaught TypeError: Argument 1 passed to Symfony\\Component\\HttpFoundation\\ParameterBag::__construct() must be of the type array, null given + $body = new \stdClass(); + } if($body !== null){ $body = json_encode($body, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); }