如何修复401未经授权的响应WP Rest API

问题描述 投票:0回答:1

我正在向我们网络上的另一个wordpress网站发出请求,如下所示。

    //Send the request to update the submission post
    $response = wp_remote_request( $this->urls->assign_url, array(
            'headers'     => array(
                'Content-Type' => 'application/json; charset=utf-8',
                'Authentication' => 'Basic '.base64_encode('somename:somepassword')
            ),
            'body'        => json_encode($array),
            'method'      => 'POST',
            'data_format' => 'body'
        )
    );
  • 我通过ajax发出此请求。
  • 正在调用回调函数并发送回数据。
  • 我还登录了远程站点。
  • Im使用随机数,并且标题中被授权的用户是有效用户。

我一直想回来的是:

body: "{"code":"rest_not_logged_in","message":"You are not currently logged in.","data":{"status":401}}"

自从我更新了远程wordpress版本以来,我才刚刚开始获取此信息。在此之前一切正常。

任何想法。

wordpress wordpress-rest-api
1个回答
0
投票

我相信,为了对您想要的方式进行身份验证,您需要使用插件-内置身份验证方法不适用于异地请求,因为它基于cookie。

https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/#authentication-plugins

© www.soinside.com 2019 - 2024. All rights reserved.