我正在尝试使用(POST
)Wordpress
来bash
到我的cURL
网站,但用户授权似乎不起作用。
到目前为止,我一直在尝试的是
curl \
-u ${USERNAME}:${PASSWORD} \
-X POST \
-H "Content-Type: application/json" \
-d '{"title": "this is a test"}' \
--url http://mywebsite.com.br/wp-json/wp/v2/posts/
{
"code": "rest_cannot_create",
"message": "Sorry, you are not allowed to create posts as this user.",
"data": {"status": 401}
}
我在做什么错?也许-u
标志不是我要寻找的标志?这就是我通常在使用BasicAuth
时尝试的方法;这里不是这样吗? wp-json
规格正确吗?
在问题中,我正在使用Basic Authentication
,它实际上是需要启用。
您可以通过从Github下载WP Basic Auth插件,然后在您的Wordpress网站中上载,安装和激活它来进行操作。
完成后,问题的代码应该可以正常工作。