未捕获(承诺)错误:请求失败,状态码为401 axios wp-api POST

时间:2017-06-01 14:15:29

标签: axios wp-api oauth-1.0a

我正在使用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工作,但不能让它工作。

p.s这篇文章中的所有标记等都是例如。

0 个答案:

没有答案
相关问题