Tencent / Biny

Biny is a tiny, high-performance PHP framework for web applications
BSD 3-Clause "New" or "Revised" License
1.69k stars 257 forks source link

使用 axios 发送POST 请求时,无法正常接收到数据 #138

Open 3DMXM opened 2 years ago

3DMXM commented 2 years ago

ts 请求代码 function GetUser() { axios.post("/render/GetUser", { user: "111" }).then((res: any) => { console.log(res); }) }

PHP接收代码 public function action_GetUser(){ $user = $this->request->post("user"); $this->json([ "code"=>"00", "user"=>$user ]); }

请求返回 {"code":"00","user":null}

QQ截图20220811113747 QQ截图20220811113804 QQ截图20220811113908 QQ截图20220811113917

billge1205 commented 2 years ago

看起来你这个并不是表单形式(x-www-form-urlencoded)的post参数格式,而是json格式的 可以尝试用 $this->request->json('user') 获取看看呢

3DMXM commented 2 years ago

恩,$this->request->json('user') 可以获取到了,谢谢