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');
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745472059a4629178.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