Ionic 3 WP-REST API Post request 401 (unauthorized) error

浪子不回头ぞ 提交于 2019-12-24 18:23:21

问题


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


回答1:


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

verifySsl: false,
queryStringAuth: true

Any post request requires an https connection.



来源:https://stackoverflow.com/questions/52104346/ionic-3-wp-rest-api-post-request-401-unauthorized-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!