怎么实现接口接收application/json数据写入内容中
现在的api接口都是x-www-form-urlencoded数据
我要怎么实现在body里面使用json数据发送post请,让后台接受数据写入内容文章的数据库中。
body json:
{
"title": "标题",
"content": "内容",
"thumb": "关键帧",
"catid": "栏目id",
"keywords": "关键词",
"description": "描述",
"author": "系统管理员"
}
header('Content-type: application/json');参考文档:《主程序运行之后 cms_init》 先判断是否api提交,然后加上面代码\Phpcmf\Hooks::app_on('appname', 'cms_init', function() { if (IS_API or IS_API_HTTP) { header('Content-type: application/json'); } });注意,任意接口提交数据要放在data数组中再提交,比如:
data["title"] = "标题"
data["content"] ="内容",
你,修改一下,试试吧!