admin管理员组文章数量:1426644
I have a server (server 1) which send requests to another server (server 2) where WordPress is installed and I am using their (server 2) WP REST API.
The problem is that I can't create/send wp-nonce
from server 1 to server 2, and I am getting the following response:
{
"code": "rest_not_logged_in",
"message": "You are not currently logged in.",
"data": {
"status": 401
}
}
I know that is not easy to disable nonce for REST API, but what is the proper way to send requests from another server to the WP REST API ?
I have a server (server 1) which send requests to another server (server 2) where WordPress is installed and I am using their (server 2) WP REST API.
The problem is that I can't create/send wp-nonce
from server 1 to server 2, and I am getting the following response:
{
"code": "rest_not_logged_in",
"message": "You are not currently logged in.",
"data": {
"status": 401
}
}
I know that is not easy to disable nonce for REST API, but what is the proper way to send requests from another server to the WP REST API ?
Share Improve this question edited May 22, 2019 at 22:19 butlerblog 5,1313 gold badges28 silver badges44 bronze badges asked May 22, 2019 at 20:25 gdfgdfggdfgdfg 1721 silver badge15 bronze badges 5 |2 Answers
Reset to default 2Since your specific scenario is a remote application making a request to WordPress you'll need to explore additional authentication methods available via plugins for the REST API. I won't make any specific recommendations since I don't know your use case in detail but I'm sure you will find one that works well.
Try adding the following to your theme's functions.php file at the top. This will allow you to use Cross Domain calls from your functions.php.
function add_cors_http_header(){
header("Access-Control-Allow-Origin: *");
}
add_action('init','add_cors_http_header');
本文标签: Send request to WordPress REST API
版权声明:本文标题:Send request to WordPress REST API 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745472058a2659794.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
rest-api-oauth1
(which is free) and on the server 1 - NodeJS -Request
library withOAuth 1.0a
library. I think, it works. – gdfgdfg Commented May 22, 2019 at 23:05