当我将JSON数据发布到Wordpress网站时出错 [英] Error when I POST JSON data to wordpress site
问题描述
我的命令是: curl -X POST --user"admin:admin"https://website.com/wp-json/wp/v2/posts/-H"Content-Type:application/json"-d {标题":测试",内容":内容",状态":草稿"}
我得到的答复: {"code":"rest_invalid_json","message":传递无效的JSON正文.","data":{"status":400,"json_error_code":4,"; json_error_message"::"语法错误"}}
谢谢!
推荐答案
好,这是Windows特有的问题,我想大多数人都在运行unix/linux客户端,因此这不适用于他们.我在这里找到了解决方案: https://stackoverflow.com/a/7173011/15161479
Ok, this was a windows specific problem, I guess most people out there are running unix/linux clients so this doesn't apply to them. I found the solution here: https://stackoverflow.com/a/7173011/15161479
问题在于Windows上的卷曲,引号需要转义.我还做了其他几件事,例如安装了应用程序密码"插件.
The issue is with curl on windows, the quotes need to be escaped. I also did a couple other things like installing the "Application Passwords" plugin.
这是我的命令现在的样子 curl --user用户:应用程序密码"http://website.com/wp-json/wp/v2/posts/-H"Content-Type:application/json"-数据"{",标题",:",测试",内容",内容";内容",状态",草稿",}","
"
This is what my command looks like now
curl --user "user:application password" http://website.com/wp-json/wp/v2/posts/ -H "Content-Type: application/json" --data "{"""title""":"""test""","""content""":"""Content""","""status""":"""draft"""}"
希望这对其他人有帮助!
Hope this helps some other people out there!
这篇关于当我将JSON数据发布到Wordpress网站时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!