unabe使用wordpress api发布

时间:2017-04-14 04:51:53

标签: wordpress wordpress-rest-api wp-api

请不要将其标记为重复。这些帖子的解决方案似乎无法奏效。

我想使用curl远程发布我的wordpress博客。

我正在使用此curl命令发布到wordpress

curl -D- -X POST -H "Authorization: Basic bTRtdxXM6R3JTcnYyMDA299999" -H "Content-Type: application/json" --data '{"title": "this is my new post sent from curl","content": "This is the content","status": "publish"}' "http://mywebsite.com/wp-json/wp/v2/posts

我得到的回应是

    HTTP/1.1 401 Unauthorized
Date: Thu, 13 Apr 2017 19:47:42 GMT
Content-Type: application/json; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __cfduid=d2221a0a91149358bf8744eb3d5816cea1492112861; expires=Fri, 13-Apr-18 19:47:41 GMT; path=/; domain=.mywebsite.com; HttpOnly
X-Powered-By: PHP/5.6.30
X-Robots-Tag: noindex
Link: <http://mywebsite.com/wp-json/>; rel="https://api.w.org/"
X-Content-Type-Options: nosniff
Access-Control-Expose-Headers: X-WP-Total, X-WP-TotalPages
Access-Control-Allow-Headers: Authorization, Content-Type
Allow: GET
Vary: Accept-Encoding,User-Agent
Server: cloudflare-nginx
CF-RAY: 34f0f046a79f081d-SIN

{"code":"rest_cannot_create","message":"Sorry, you are not allowed to create posts as this user.","data":{"status":401}}

我已经尝试了所有我能做但却无法工作的东西。有人建议将以下内容添加到没有工作的htaccess

# BEGIN WP BASIC Auth
<IfModule mod_rewrite.c>
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
</IfModule>
# END WP BASIC Auth

我也试过安装https://wordpress.org/plugins/rest-api/插件。

当前PHP版本:5.6 主持Godaddy经济主办。 Wordpress版本:WordPress 4.7.3

请帮助,我已经尝试了几天,似乎没有任何解决方案可行。

0 个答案:

没有答案