In my wp site I installed and activated JSON Basic Authentication.
Then I try to make request from third-party site:
$headers = array(
‘Authorization’ => ‘Basic ‘ . base64_encode( ‘login’ . ‘:’ . ‘password’ )
);
$url = ‘https://mysite.com/wp-json/wp/v2/posts’;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
echo $response;
In response I receive
{“code”:”restx_logged_out”,”message”:”Sorry, you must be logged in to make a request.”,”data”:{“status”:401}}
So, what’s wrong?