在我的WordPress REST端点上,我登录了wordpress,返回了一个nonce,如下所示:
PHP
$authenticated = wp_authenticate( $userID , $password );
$isAuthenticated = ( $authenticated instanceof \WP_User ) ? TRUE : FALSE;
if ( $isAuthenticated )
{
$responseData[ "nonce" ] = wp_create_nonce( "rest" );
return rest_ensure_response( $responseData );
}然后,我通过axios将nonce返回到PHP以验证它,并且它工作了!
JS:
let axiosSettings = {
baseURL: "http://site.localhost",
url: "/wp-json/id3/test/verify",
method: "POST",
data: {
n: this.state.nonce
}
}但是当我把nonce放在报头X-WP-Nonce中时,
let axiosSettings = {
baseURL: "http://site.localhost",
url: "/wp-json/id3/test/pc",
method: "POST",
data: {
n: this.state.nonce
},
withCredentials: true,
headers: {
"X-WP-Nonce": this.state.nonce
}
};它告诉我
Cookie nonce无效,拒绝访问我的REST API。为什么会这样呢?
发布于 2017-10-06 21:21:04
后来进行了大量的搜索...操作需要是"wp_rest“。
https://stackoverflow.com/questions/46605470
复制相似问题