Tencent / Biny

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

(我又来提issues)开启RESTful Api后貌似getParam方法接不到参数 #37

Closed lordGuan closed 6 years ago

lordGuan commented 6 years ago

action开启了RESTful Api在初始化时this->param是通过file_get_contents('php://input')赋值的,但是我多次调试发现file_get_contents('php://input')是没有内容,不知道是什么情况

billge1205 commented 6 years ago

GET的请求 可以直接在function的参数中传递 其他参数会在file_get_contents('php://input')里 不知道你的是什么方式的请求

billge1205 commented 6 years ago

做了兼容 GET参数也可在 $this->getParam中获取 优先级GET > data数据

lordGuan commented 6 years ago

我查了很多文章,也没有搞清楚为什么file_get_contents('php://input')获取不到数据

billge1205 commented 6 years ago

POST的情况下能正常获取吗 还是只有 PUT DELETE 这种会获取失败 感觉是不是跟php配置或者php临时缓存的读写权限有关

lordGuan commented 6 years ago

刚才我又确认了一下,从页面用ajax进行PUT是OK的,用phpstorm的工具和postman就不行。POST请求时没有问题的。

billge1205 commented 6 years ago

是不是被csrf拦截了?页面ajax里有注册csrf验证信息的 在action里添加 protected $csrfValidate = false; 绕过csrf 验证看看

lordGuan commented 6 years ago

并不好使(捂脸 刚才我抓了一下postman和phpstorm的请求,发现content-length都是0,会是这个的影响么

billge1205 commented 6 years ago

Content-Type 设置成 application/x-www-form-urlencoded ? 数据传 abc=123&cba=321这种 如果是application/json 的话 数据应该传json {“abc”:123} 类似这种

lordGuan commented 6 years ago

果了个然,restful client我没加content-type,参数得用text才能传的了。postman的Content-Type倒是没问题,但是body默认的form-data。原来如此,学到了学到了