关于request-> request()不能接收json格式数据的问题
经测试,$_REQUEST在小程序、h5是可以接收json以及数组等格式的数据,但是在app的部分请求中,如果没有修改请求类型为form的话,传过来的值会是json的数据,这时request接收的数据就为空了!
解决方案:
thinkphp/library/think/request.php 802行的request()方法修改为:
public function request($name = '', $default = null, $filter = '')
{
if (empty($this->request)) {
$content = $this->input;
if (empty($_REQUEST) && false !== strpos($this->contentType(), 'application/json')) {
$this->request = (array) json_decode($content, true);
} else {
$this->request = $_REQUEST;
}
}
if (is_array($name)) {
$this->param = [];
$this->mergeParam = false;
return $this->request = array_merge($this->request, $name);
}
return $this->input($this->request, $name, $default, $filter);
}
这样就可以解决了,希望能帮助到大家