我正在使用 react 作为 wordpress 网站的前端。我正在尝试使用 axios 和 wp-api 从表单将数据发布到 wordpress。以下是我尝试执行此操作的方法,但我不断得到:
代码:“rest_cannot_create”,消息:“对不起,您不能以该用户的身份创建帖子。”,...} 代码:“rest_cannot_create”数据:{status:401} 消息:“对不起,您不允许创建帖子作为这个用户。”
const AUTH_OBJ = 'OAuth oauth_consumer_key="hMZQANcBegerge",oauth_token="eger",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1496325588",oauth_nonce="oligrgGalWv",oauth_version="1.0",oauth_signature="v%2f4tiFyH1H46XKBXp6orthejy8Q44%253D"';
const URL = 'http://TEST.COM/wp-json/wp/v2/TEST';
axios.post(URL,
querystring.stringify({
name: this.props.name
}), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': AUTH_OBJ
}
}).then((response) => {
console.log('Response: ', response);
if(response.status === 200) {
console.log('RESPONSE 200');
}
});
我让它使用 PostMan 工作,但不能让它工作。
ps 这篇文章中的所有代币等都是例如虚构的。