PHP技术论坛

标题: my.request替换my.httpRequest注意事项 [打印本页]

作者: admin    时间: 2021-4-1 11:18
标题: my.request替换my.httpRequest注意事项
最近打算把项目中网络请求替换成my.request,发现后端无法获取到数据,表现为POST没有数据 GET有数据,换成my.httpRequest又正常,仔细看了官方文档发现问题出现这里

若方法为 GET,会将数据转换成 query string: encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...

若方法为 POST 且 headers['content-type'] 为 application/json ,会对数据进行 JSON 序列化。

若方法为 POST 且 headers['content-type'] 为 application/x-www-form-urlencoded ,会将数据转换成 query string:encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...



所以默认是application/json 后台获得到的并不是POST参数

作者: admin    时间: 2021-4-1 11:20
如果项目是从微信转过来的注意content-type这里是小写 微信是大写




欢迎光临 PHP技术论坛 (http://php.hh85.com/) Powered by Discuz! X3.2