【问题标题】:Ionic 3 WP-REST API Post request 401 (unauthorized) errorIonic 3 WP-REST API 发布请求 401(未经授权)错误
【发布时间】:2019-02-05 19:56:12
【问题描述】:

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

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));
    })

  }

顺便说一下,关键客户和秘密是正确的

【问题讨论】:

  • 这可能意味着您实际上未经授权将数据发布到此 API。您不应该在此请求中传递授权标头吗?
  • 如何通过呢?在哪里?
  • 你怎么知道 api 正在工作?
  • 发布您的WooCommerce 课程。

标签: javascript angular typescript ionic3 woocommerce-rest-api


【解决方案1】:

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

verifySsl: false,
queryStringAuth: true

任何post 请求都需要https 连接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 2016-02-09
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多