【发布时间】:2020-07-05 23:31:05
【问题描述】:
我正在向我们网络上的另一个 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 发出此请求。
- 正在调用回调函数并发送回数据。
- 我也登录了远程站点。
- 我使用的是随机数,并且在标题中获得授权的用户是有效用户。
我不断回复的是:
body: "{"code":"rest_not_logged_in","message":"You are not currently logged in.","data":{"status":401}}"
自从我更新了远程 wordpress 版本后,我才刚刚开始得到这个。在那之前它工作得很好。
任何想法。
【问题讨论】:
-
您使用的是默认认证还是插件?我在您的请求中没有看到 nonce,但可能是误解。
-
Nonce 在 js 中传递给回调函数,并在这个 http 请求之前检查。我没有使用插件,这只是默认用户身份验证。该用户是远程站点上的简单管理员用户。
标签: wordpress wordpress-rest-api