Ionic 3 WP-REST API发布请求401(未经授权)错误 [英] Ionic 3 WP-REST API Post request 401 (unauthorized) error

查看:154
本文介绍了Ionic 3 WP-REST API发布请求401(未经授权)错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个简单的应用程序,以通过wp-rest api在Wordpress(woocommerce)中创建用户. 但是当我尝试创建新客户时,它在控制台中显示401 Unauthorized错误.这是我的要求代码.

I am developing a simple application to create a user in Wordpress (woocommerce) through wp-rest api. but when I try to create a new customers it shows 401 Unauthorised error in console. heres is my code for request.

signup(){

    let customerData = {
      customer : {}
    }

    customerData.customer = {
      "email": this.newUser.email,
      "first_name": this.newUser.first_name,
        ...
      "billing_address": {
        "first_name": this.newUser.first_name,
        ...
      },
      "shipping_address": {
        "first_name": this.newUser.first_name,
          ...

      }
    }

    if(this.billing_shipping_same){
      this.newUser.shipping_address = this.newUser.shipping_address;
    }
    this.WooCommerce.postAsync('customers', customerData).then( (data) => {

      console.log(JSON.parse(data.body));
    })

  }

关键客户&秘密是正确的

by the way the key client & secret are correct

推荐答案

您需要一个https连接,将以下几行添加到woocommerce初始化中:

You need an https connection, add the following lines to your woocommerce init :

verifySsl: false,
queryStringAuth: true

任何post请求都需要一个https连接.

Any post request requires an https connection.

这篇关于Ionic 3 WP-REST API发布请求401(未经授权)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆